【问题标题】:Adding a new tab, I have no idea how添加一个新标签,我不知道如何
【发布时间】:2012-11-14 09:56:26
【问题描述】:
我正在使用 XCode 4.3,并且我正在按照我书中的示例创建一个标签栏应用程序(可能用于 XCode 版本
默认情况下,新创建的标签栏应用程序包括 2 个标签。你可以看看我的截图
现在我想添加另一个选项卡(如图所示的 TabExampleThirdViewControler)。但我不知道如何使它成为第三个标签。我的旧书说我需要将它链接到 MainWindow,但正如您在图像中看到的那样,根本没有 MainWindow 文件。
新版本 XCode 的这种更新让像我这样的初学者很困惑。感谢您提供的任何指导。
【问题讨论】:
标签:
iphone
objective-c
cocoa-touch
ios4
tabs
【解决方案1】:
我不确定您使用什么方法来创建标签。但是看看我的。我总是创建这样的标签。这很容易实现:
Appdelegate.h
UITabBarController *tabBarController;
// set properties
Appdelegate.m
// Synthesize
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
// Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController
Search * search = [[Search alloc] init];
UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search];
Nearby* nearby = [[Nearby alloc] init];
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];
Map* map = [[Map alloc] init];
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];
AboutUs* aboutUs = [[AboutUs alloc] init];
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];
Favorites* favorites = [[Favorites alloc] init];
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];
NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
然后在上面提到的每个视图控制器中你需要实现
- (id)init {}
您可以在其中设置选项卡名称和图像。
我总是遵循这种方法,而且它永远不会失败。选项卡始终可见。