iOS6 尝试从 UIView 创建 UITabBarController



我正在尝试从UIViewController以编程方式创建一个UITabBar。我目前正在使用此算法。但是,我遇到了一个问题。谁能告诉我我缺少什么?

-(void)loadView{
    UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    contentView.backgroundColor = [UIColor whiteColor];
    self.view = contentView;
    TabControllerHelper *tabControllerHelper = [[TabControllerHelper alloc]initWithNibName:@"TabControllerHelper" bundle:[NSBundle mainBundle]];
    tabControllerHelper.title = @"First";
    TabControllerHelper *tabControllerHelper1 = [[TabControllerHelper alloc]initWithNibName:@"TabControllerHelper" bundle:nil];
    tabControllerHelper1.title = @"Second";
    //dvdInfoController.tabBarItem.image = [UIImage imageNamed:@"dvdicon.png"];
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    tabBarController.view.frame = CGRectMake(0, 0, 320, 460);
    // Set each tab to show an appropriate view controller
    [tabBarController setViewControllers:[NSArray arrayWithObjects:tabControllerHelper, tabControllerHelper1, nil]];
    [self.view addSubview:tabBarController.view];
}

我收到的错误:

2012-12-11 01:34:27.581 SampleUITabView[7134:c07] -[__NSCFType _tabBarItemClicked:]: unrecognized selector sent to instance 0x7574230
2012-12-11 01:34:27.582 SampleUITabView[7134:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType _tabBarItemClicked:]: unrecognized selector sent to instance 0x7574230'
*** First throw call stack:

您正在做一些"视图控制器包含"的事情。一种方法可能是不理会loadView,让它做基本的事情。

在viewDidLoad中执行视图控制器包含,例如

自加子控制器...self.view add子视图:...子控制器确实移动到父...

因为仅将选项卡栏控制器视图

添加为子视图,您不一定会获得选项卡栏控制器行为。

最新更新