视图一次只能与一个视图控制器关联(UISegmentedControl) [英] A view can only be associated with at most one view controller at a time (UISegmentedControl)

查看:337
本文介绍了视图一次只能与一个视图控制器关联(UISegmentedControl)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello iOS6上的模拟器中发生错误。

Hello The error occurs in the emulator on 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

App crashes when selected == 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

SearchHotelsViewController.xib

推荐答案

确保您的ViewController不包含其他视图控制器对象。例如,如果您的主视图控制器有一个tableview,请不要将UITableViewController放入。它曾用于传递iOS 5,但在iOS 6中它们不允许这样做。

Make sure your ViewController does not contain another view controller object. For example if your main view controller has a tableview, do not put the UITableViewController with in. It this used to pass in iOS 5, but in iOS 6 they will not allow this.

这篇关于视图一次只能与一个视图控制器关联(UISegmentedControl)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆