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」であるいくつかのことを行っています。1 つの方法は、loadView をそのままにして、基本的なことだけを実行させることです。

そして、viewDidLoadでは、次のようなView Controllerの封じ込めを行います

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

タブバー コントローラー ビューをサブビューとして追加するだけでは、必ずしもタブバー コントローラーの動作が得られるとは限りません。

于 2012-12-10T17:49:49.590 に答える