UITabBarController to load subviews
I am kind of stuck and would appreciate any ideas on what I did wrong. I created programmatically a NSObject which holds a UITabBarController to which three ViewControllers are added:
UITabBarController tabBarController = [[UITabBarController alloc] init];
ControllerOne = [[OneViewController alloc] initWithNibName:@"OneView" bundle:nil];
ControllerTwo = [[TwoViewController alloc]initWithNibName:@"TwoView" bundle:nil];
ControllerThree = [[ThreeViewController alloc] initWithNibName:@"ThreeView" bundle:nil];
NSMutableArray *viewControllers = [[NSMutableArray alloc] initWithCapacity:3];
[viewControllers addObject:ControllerOne];
[viewControllers addObject:ControllerTwo];
[viewControllers addObject:ControllerThree];
[tabBarController setViewControllers:viewControllers];'
I now display the tabBarController's view
viewController.modalTransitionStyle = transitionStyle;
[self presentModalViewController:viewController animated:YES];
with viewController being the just created tabBarController.
Th开发者_开发问答e view changes fine, displaying the tabbar correctly (Icons and titles) but fails to show e.g. OneViewController's view. I assume that the view is not loaded since the - (void)viewDidLoad
is not being called for any of the subview controllers.
I would appreciate any suggestions.
Thanks, equi
Are you sure your nib names are how you have typed them? It's not called OneViewController.xib?, for example?
I sorted out the issue. The above code actually worked, reason for the view not appearing was that I accidentally synthesised 'view' in the UIViewController derivative.
精彩评论