In the application I’m trying to develop I have UINavigationController as a root controller. I initialize views using pretty common code:
MySubclassOfViewController *vc = [[MySubclassOfViewController alloc]
initWithNibName:@"MySubclassOfViewController"
bundle:nil];
vc.title = @"A title";
[self.navigationController pushViewController:vc animated:YES];
[vc release];
After a succession of some views I want to load UITabBarController.
-
Is there a way to desing the nib file and create an instance of UITabBarController the same way as above?
I know I can do this programmatically or by explicitly declaring an outlet and connecting it with the controller in the nib. It’s also possible to initialize the controller using something likeNSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"MySubclassOfViewController" owner:self options:nil]; self = [objects objectAtIndex:0]; [objects release];But can I make it without extra work & typing?
- Let’s say I define a subclass of UITabBarConroller (although I know it’s discouraged in the Apple docs, but just out of curiosity). When I make an instance of the subclass, can I somehow load the superclass part out of a nib?
I’ve solved my problem myself. After some research, I came to these conclusions.
UITabBarController *tbc = [[UITabBarController alloc] initWithNib...) Either there should be an extra outlet for the controller, or the controller should be explicitlyalloc/init‘ed (but notinitWithNibName), or it could be instantiated usingloadNibNamed. That’s it. The reason for this is that the tab bar controller doesn’t have outlets declared to connect them to children view controller. (For more details on loading nibs check Development Chaos Theory blog).Any comments on this? 🙂