如何使用TabBar创建应用程序?

时间:2015-12-09 10:35:48

标签: ios objective-c uitableview xcode7 uitabbar

我想要一个带有3个标签的标签栏。我希望在每个标签视图中都有一个表格视图。我有3个表视图控制器,我想在3个选项卡中添加这些视图。我不知道怎么做。

2 个答案:

答案 0 :(得分:0)

创建UITabBarController并在ViewDidLoad中添加如下的tableViewControllers:

    let item1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("firstTableViewController") as! UITableViewController

    let item2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("secondTableViewController") as! UITableViewController
    let item3 = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("thirdTableViewController")  as! UITableViewController


    let controllers = [item1,item2, item3]
    self.viewControllers = controllers

使用您的标识符和名称更改标识符和storyBoard名称

答案 1 :(得分:0)

EmployeeViewController *evc = [[EmployeeViewController alloc]init];
    UINavigationController *nc1 = [[UINavigationController alloc]initWithRootViewController:evc];
FavoriteViewController *fvc = [[FavoriteViewController alloc]init];
    UINavigationController *nc2 = [[UINavigationController alloc]`initWithRootViewController:fvc`];
 self.tabBarController = [[UITabBarController alloc]init];
NSArray* controllers2 = [NSArray arrayWithObjects:nc1,nc2, nil];
        self.tabBarController.viewControllers = controllers2;
        self.window.rootViewController = self.tabBarController;