如何使用目标c在iphone中添加UITabBar [英] How to add UITabBar in iphone using objective c

查看:141
本文介绍了如何使用目标c在iphone中添加UITabBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式为iphone应用添加添加UITabBar。需要一些建议和示例代码。

How to add add UITabBar programmatically for iphone app. Need some suggestion and sample code.

推荐答案

- (void) setUpTabBar {
    FirstViewController *firstViewController = [[FirstViewController alloc]init];
    firstViewController.title = @"First View";
    firstViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemSearch tag:0];
    UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:firstViewController];

    SecondViewController *secondViewController = [[SecondViewController alloc]init];
    secondViewController.title = @"Second View";
    secondViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1];
    UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:secondViewController];

    ThirdViewController *thirdViewController = [[ThirdViewController alloc]init];
    thirdViewController.title = @"Third View";
    thirdViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemRecents tag:2];
    UINavigationController *thirdNavController = [[UINavigationController alloc]initWithRootViewController:thirdViewController];

    ForthViewController *forthViewController = [[ForthViewController alloc]init];
    forthViewController.title = @"Forth View";
    forthViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory tag:2];
    UINavigationController *forthNavController = [[UINavigationController alloc]initWithRootViewController:forthViewController];

    tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
    tabBarController.viewControllers = [[NSArray alloc] initWithObjects:firstNavController, secondNavController, thirdNavController, forthNavController, nil];
    tabBarController.delegate = self;             
    [self sizeViewToAvailableWindow:[tabBarController view]];

    [firstNavController release];
    [firstViewController release];

    [secondNavController release];
    [secondViewController release];

    [thirdNavController release];
    [thirdViewController release];

    [forthNavController release];
    [forthViewController release];
}

以下是以编程方式制作TabBarController的代码。
希望这会对你有帮助。

Here is the code for making TabBarController programmatically. Hope this will help you.

这篇关于如何使用目标c在iphone中添加UITabBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆