tags:

views:

224

answers:

2

Hi I have a small doubt, I have 3 Nib Files:

  1. ConfigureContacts.xib
  2. CallContactsViewController.xib
  3. MainWindow.xib

When Application starts I do:

[window addSubview:callContactsViewController.view];
[window makeKeyAndVisible];

So that the CallContactsViewController.xib is loaded.

Inside CallContactsViewController.xib there is a button, that when presses jumps to:

-(IBAction)configureContacts:(id)sender
{
    configureContacts = [[ConfigureContacts alloc] initWithNibName:@"ConfigureContacts" bundle:nil];
    [self.view addSubview:configureContacts.view];   

}

The idea is that when the button is pressed it goes to the "next window" which is the other .xib file. Is this the correct way of changing through xibs ? Am I wasting memory here ?

Thanks in advance

A: 

is ConfigureContacts a ViewController subclass? (It looks like it is)

if so you would actually do something like this

-(IBAction)configureContacts:(id)sender
{
    configureContacts = [[ConfigureContacts alloc] initWithNibName:@"ConfigureContacts" bundle:nil];

    [self pushviewController:configureContacts animated:YES];
}

My Guess this is what you want to do.

[self.view addSubview:configureContacts.view] should work as well however it will change only part of the view and keep you on the same 'Window' so to speak.

Bluephlame
Yes ConfigureContacts is a ViewController subclass.Using pushviewController yields a warning, CallContactsViewController may not respond to -pushViewController.It generates when runned an EXCEPTION:[CallContactsViewController pushviewController:animated:]: unrecognized selector sent to instance 0xd1b2a0
daniel
A: 

pushViewController is a method from UINavigationController, which is used for managing hierarchical viewControllers. It sounds like that might be what you're trying to do here, in which case adding a UINavigationController to your code might be the way to go.

Alternatively, you could implement a third UIViewController that owns both CallContrats and ConfigureContacts and is responsible for switching between them.

Check out the sample code from Beginning iPhone Development 3. Specifically, check out the programs "06 View Switcher" and "09 Nav". I think they'll have the code that you're looking for.

niels