Simple TabBar on a View for 2 Other views?
I wanna have a SettingViewMain with a TabBar, which can Flip between SettingView1 and SettingView2.
I tried this simple work since 3 hours and try nearly all tutorials I found, but I don't get it to work.
When I try to add a TabBar programmatically, I can flip between this 2 views, but in this views itself the TabBar is not shown, don't know why. When I add a TabBarController, this is not shown at all.
So, simlpy: How do 开发者_Go百科I add a TabBar on a MasterView (not a AppDelegate-Window or something like this) and get the TabBar to switch between View1 and View2?
You can instantiate a UITabBarController using its alloc and init methods. Instantiate both other ViewControllers and add them to an array. After doing so, add it's view to your 'MasterView'.
Code:
UITabBarController *tab = [[UITabBarController alloc] init];
UIViewController *controller1 = [[UIViewController alloc] init];
UIViewController *controller2 = [[UIViewController alloc] init];
NSArray *controllers = [[NSArray alloc] initWithObjects:controller1, controller2, nil];
[tab setViewControllers:controllers];
[[self view] addSubview:[tab view]];
Or something closely compared to this.
Good luck!
Bryan
精彩评论