gpt4 book ai didi

objective-c - UIViewControllerHierarchyInconsistency 清除关联

转载 作者:行者123 更新时间:2023-11-29 13:24:02 27 4
gpt4 key购买 nike

我知道这个问题以前发布过,但我找到的答案与这种情况不符

运行2年前在Xcode 4.5.1中编写的应用程序后出现异常。

这是:

exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! <UIView: 0xaa9c4f0; frame = (0 0; 320 367); autoresize = W+H; layer = > is associated with <TabledReservationListController: 0xaa89e80>. Clear this association before associating this view with <UIViewController: 0x9e9e310>.'

然后在几个像这样的答案中

UIViewControllerHierarchyInconsistency when trying to present a modal view controller

建议删除 nib 文件中的 viewcontroller,就像在问题图片上看到的那样。

问题是在这种情况下,我没有 viewController,这是 TabledReservationListController 的 nib 文件:

TabledReservationListView.xib

这是应用程序崩溃的代码部分:

- (void)viewDidLoad {
[super viewDidLoad];

[navigation setDelegate: self];
[self createReservationListController];

[reservationListController viewWillAppear: NO];

// in this line below
[[navigation topViewController] setView: [reservationListController view]];

[reservationListController viewDidAppear: NO];

[[self view] addSubview: [navigation view]];
CGRect r = [[self view] frame];
r.origin.y = 0;
[[navigation view] setFrame: r];

[reservationListController setNavigationController: navigation];
}


- (void)createReservationListController {
TabledReservationListController *res_ =
[[TabledReservationListController alloc] initWithNibName: @"TabledReservationListView"
bundle: nil];
[self setReservationListController: res_];
[res_ release];

[[[self navigation] topViewController] setTitle: @"Available Tables"];
}

问候,也许有人可以提供帮助。

最佳答案

您不应该调用 viewWillAppearviewDidAppear。这些应该是框架调用您的方法。

与其尝试将 reservationListController 的 View 提供给不同的 Controller ,不如推送 reservationListController

关于objective-c - UIViewControllerHierarchyInconsistency 清除关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13624820/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com