こんにちはこのエラーは、iOS6のエミュレータで発生します。ビューは一度に複数のビューコントローラ(UISegmentedControl)にのみ関連付けることができます
*** 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;
のAppは== 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
正解のために+1、iOS5はアプリをクラッシュさせないが、iOS6は持っている。 – Girish