gpt4 book ai didi

objective-c - 一个 View 一次最多只能与一个 View Controller 相关联(UISegmentedControl)

转载 作者:太空狗 更新时间:2023-10-30 03:16:19 25 4
gpt4 key购买 nike

您好 iOS 6 模拟器出现错误

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;

selected == 1true 时应用崩溃

-(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

SearchHotelsViewController.xib

最佳答案

确保您的 ViewController 不包含另一个 View Controller 对象。例如,如果您的主视图 Controller 有一个 TableView ,请不要将 UITableViewController 放在其中。它过去常常在 iOS 5 中传递,但在 iOS 6 中它们将不允许这样做。

关于objective-c - 一个 View 一次最多只能与一个 View Controller 相关联(UISegmentedControl),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13357788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com