您好 iOS 6 上的模拟器出现错误。
由于未捕获的异常“UIViewControllerHierarchyInconsistency”而终止应用程序,原因:“一个视图一次最多只能与一个视图控制器相关联!查看 <UIView: 0xa3ae880; 帧 = (0 0; 320 367); 自动调整大小 = 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