你好,错误出现在 iOS 6 模拟器中。
由于“一个视图只能同时与一个视图控制器关联!”,因此未捕获的异常'UIViewControllerHierarchyInconsistency'导致应用程序终止。 视图<UIView:0xa3ae880; frame=(0 0;320 367); autoresize=W+H; layer=<CALayer:0xa3ae8e0>>与<SearchHotelsViewController:0xa3a6a20>相关联。 在将此视图与<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;
当selected == 1
为true
时,应用程序崩溃。
-(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