adubr
adubr

Reputation: 777

Loading/initializing secondary UITabBarController from/with nib

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.

  1. 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 like

    NSArray *objects = [[NSBundle mainBundle]
                         loadNibNamed:@"MySubclassOfViewController"
                         owner:self
                         options:nil];
    self = [objects objectAtIndex:0];
    [objects release];
    

    But can I make it without extra work & typing?

  2. 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?

Upvotes: 1

Views: 1034

Answers (1)

adubr
adubr

Reputation: 777

I've solved my problem myself. After some research, I came to these conclusions.

  1. It's not possible to do it the same way (i.e. UITabBarController *tbc = [[UITabBarController alloc] initWithNib...) Either there should be an extra outlet for the controller, or the controller should be explicitly alloc/init'ed (but not initWithNibName), or it could be instantiated using loadNibNamed. 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).
  2. If the previous answer was 'yes', then all I had to do was to set the custom class in the Interface Builder to my subclass. This works for other objects (well, may be except the UINavigationController, which is not intended for subclassing as well). But since the 'simple' initialization of a tab bar controller is impossible, this is impossible too.

Any comments on this? :)

Upvotes: 1

Related Questions