在 IB 中,我可以将底部栏设置为 View 的标签栏,如下图所示,但是如何通过 implement(.m) 文件中的代码设置它?
谢谢
最佳答案
为您要使用的 UIViewController
创建一个 NSArray
。然后实例化一个 UITabBarController
并将 viewControllers
属性设置为该数组。然后将 tabBarController
的 view
添加到窗口中。所有这些都应该在 AppDelegate.m 文件中完成。例如:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *vc1 = [[UIViewController alloc] init];
UIViewController *vc2 = [[UIViewController alloc] init];
CustomViewController *vc3 = [[CustomViewController alloc] init];
NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2, vc3, nil];
[vc1 release]; [vc2 release]; [vc3 release];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:viewControllers];
[window addSubview:[tabBarController view]];
[window makeKeyAndVisible];
return YES;
}
关于iphone - 在 Objective-c 中以编程方式将底部栏设置为选项卡栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8663864/