Iphone 在Objective-c中以编程方式将底部栏设置为选项卡栏
在IB中,我可以将底部栏设置为屏幕截图下方视图的选项卡栏,但如何通过实现(.m)文件中的代码进行设置 谢谢Iphone 在Objective-c中以编程方式将底部栏设置为选项卡栏,iphone,objective-c,ios,Iphone,Objective C,Ios,在IB中,我可以将底部栏设置为屏幕截图下方视图的选项卡栏,但如何通过实现(.m)文件中的代码进行设置 谢谢 创建要使用的UIViewController的NSArray。然后实例化一个UITabBarController,并将viewControllers属性设置为此数组。然后将tabBarController的视图添加到窗口中。所有这些都应该在AppDelegate.m文件中完成。例如: - (BOOL)application:(UIApplication *)application did
创建要使用的
UIViewController
的NSArray
。然后实例化一个UITabBarController
,并将viewControllers
属性设置为此数组。然后将tabBarController
的视图添加到窗口中。所有这些都应该在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;
}
创建要使用的UIViewController
s的NSArray
。然后实例化一个UITabBarController
,并将viewControllers
属性设置为此数组。然后将tabBarController
的视图添加到窗口中。所有这些都应该在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;
}