How to add tab bar controllers to the root view of the split view controller application

帅比萌擦擦* 提交于 2019-11-30 23:10:15

you have to take UITabBarController dynaically.

In .h file

UITabBarController *tabBar;

in .m file

create objects to your classes in appDidFinish Launch

For example you have

Class1 and Class2

in appDidFinishLaunch

Class1 *obj1=[Class1 alloc]initWithNibName:@"Class1" bundle:nil]; **Class2 obj2=[Class2 alloc]initWithNibName:@"Class2" bundle:nil];*

// Master navigation controller by defaults comes with template code

// Now you have create Array for tabBar

NSArray *tabViewArray=[[NSArray alloc] initWithObjects:obj1,obj2,masterNavigationController, nil];

tabBar=[[UITabBarController alloc] init];

[tabBar setViewControllers:tabViewArray];

// now you have to edit the statement which contains splitview.viewArray repalce masterNavigataionControler with tabBar

self.splitViewController.viewControllers = [NSArray arrayWithObjects:tabBar, detailNavigationController, nil];

Try this i hope it will helps you.

in your app delegate add tabbar controller then add your view controllers to tabbar controller and set the window rootview controller to tabbar controller.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
 self.tabbar=[[UITabBarController alloc] init];

   self.vc1 = [[vc1 alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
   // do the same to other VCs
    self.tabbar.viewControllers=[NSArray arrayWithObjects:vc1,vc2,vc3,vc4, nil];


self.window.rootViewController = self.tabbar;

[self.window makeKeyAndVisible];
return YES;

}

i hope it helps :-)

All you have to do is initialize the first argument of uispliviewcontroller for view as tabbar instead of a view or you can use uisegmentedcontrol.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!