我知道此问题之前已发布过,但我发现的答案并非根据此情况
2年前在Xcode 4.5.1中运行应用程序wroten后发生异常。
这是:
异常'UIViewControllerHierarchyInconsistency', 原因:'视图一次只能与一个视图控制器关联! < UIView:0xaa9c4f0; frame =(0 0; 320 367); autoresize = W + H; layer => 与< TabledReservationListController:0xaa89e80>相关联。在将此视图与< UIViewController:0x9e9e310>相关联之前清除此关联。'
然后在像这样的几个答案中
UIViewControllerHierarchyInconsistency when trying to present a modal view controller
建议删除nib文件中的viewcontroller,就像在问号图片上看到的一样。
问题是在这种情况下,我没有viewController,这是TabledReservationListController的nib文件:
这是应用程序崩溃的代码部分:
- (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"];
}
也许有人可以帮忙,问候。
答案 0 :(得分:1)
您不应该致电viewWillAppear
和viewDidAppear
。这些应该是框架调用你的方法。
您应该推送reservationListController
,而不是尝试将reservationListController
的视图提供给其他控制器。