您好,错误发生在iOS6的模拟器中。
*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View <UIView: 0xa3ae880; frame = (0 0; 320 367); autoresize = W+H; layer = <CALayer: 0xa3ae8e0>> is associated with <SearchHotelsViewController: 0xa3a6a20>. Clear this association before associating this view with <SecondViewController: 0xa1a9e90>.'
初始化代码
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Поиск туров", @"Выбор отеля", nil]];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
self.navigationItem.titleView = segmentedControl;
[segmentedControl addTarget:self action:@selector(changeSegments:) forControlEvents:UIControlEventValueChanged];
segmentedControl.selectedSegmentIndex = 0;
self.navigationItem.title = [segmentedControl titleForSegmentAtIndex:segmentedControl.selectedSegmentIndex];
[self setView:searchTours];
SearchHotelsViewController *searchHotelsController = [[SearchHotelsViewController alloc] initWithNibName:@"SearchHotelsViewController" bundle:[NSBundle mainBundle]];
selectHotels = searchHotelsController.view;
选择时应用崩溃== 1
-(void)changeSegments:(id)sender {
NSInteger selected = [sender selectedSegmentIndex];
if (selected == 0) {
[self setView:searchTours];
}
if (selected == 1) {
[self setView:selectHotels];
}
self.navigationItem.title = [sender titleForSegmentAtIndex:selected];
}
我不明白问题出在哪里。
SearchHotelsViewController.xib
请确保您的ViewController不包含另一个视图控制器对象。例如,如果您的主视图控制器具有表视图,则不要将UITableViewController放在in中。它过去曾在iOS 5中传递,但在iOS 6中,他们不允许这样做。
[当我是白痴时遇到了这个问题,并将“ UITableViewController”对象拖到笔尖中以用作视图而不是“ UITableView”。哎呀!
当我从情节提要板中复制/粘贴到xib文件时遇到了此问题。从xib重新创建界面为我解决了此问题。
我有类似的问题。多个xib文件(有些起作用,有些却没有)都只有一个UITableView。我必须删除损坏的xib文件并创建新文件。之后,他们都工作了。