UITabBarController中的UI问题

时间:2014-03-03 10:24:08

标签: objective-c cocoa-touch uitabbarcontroller

这是源代码

  1. 问题:TabbarController无法正常工作...... 请帮帮我

    NSArray *actionButtonItems = @[searchItem, refreshItem];
    
    self.navigationItem.rightBarButtonItems = actionButtonItems;
    
    
    
    NSMutableArray *items = [[NSMutableArray alloc] init];
    
    
    [items addObject:[[UITabBarItem alloc]
                       initWithTabBarSystemItem:UITabBarSystemItemHistory tag:1]];
    
    [items addObject:[[UITabBarItem
                       alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts  tag:2]];
    
    tabBar.items = items;
    
    tabBar.delegate = self;
    
    addFriends = [[AddFriendsViewController alloc]          initWithNibName:@"AddFriendsViewController" bundle:nil];
    
    [self.tabView addSubview:addFriends.view];
    
    //[self.tabsetSelectedIndex = 0];
    
    _tabBarController.selectedIndex = 0;
    
    [self.view addSubview:_tabBarController.view];
    

2 个答案:

答案 0 :(得分:1)

致电之前

[self.tabView addSubview:addFriends.view];

你应该致电

[self.tabView setViewControllers:[NSArray arrayWithObjects: addFriends, nil]];

答案 1 :(得分:0)

设置UITabBarController的selectedViewController属性:

  self.myTabBarController.selectedViewController = myViewController;

使用如下

  self.myTabBarController.selectedViewController 
     = [self.myTabBarController.viewControllers objectAtIndex:0];