0

我正在尝试从 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:
4

1 回答 1

0

你正在做一些“ViewController Containment”的事情。一种方法可能是不理会 loadView 并让它做基本的事情。

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

self addChildController ... self.view addSubview:... childController didMoveToParent ...

因为只需将标签栏控制器视图添加为子视图,您不一定会获得标签栏控制器的行为。

于 2012-12-10T17:49:49.590 回答