views:

122

answers:

1

Hi,

What is the best way to do view management in a multiview application?

Right now I have this ViewSwitcher method/function that comes from a custom delegate I created.

The code is a whole bunch of if else like this

    MyViewController *c = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
    c.delegate = self;
    self.myViewController = c;

    [self.viewHolder insertSubview:c.view atIndex:0];
    [c release];

That works fine, but when I visited the function a second time, is there going to be 2 instances of MyViewController now or just 1?
How do I unload MyViewController when I switch to another view?

Or is there a better way to manage my views?

Thanks,
Tee

A: 

If self.myViewController is a retained property, then there will be two instances of MyViewController up until this line:

self.myViewController = c;

... at that point the synthesized accessors will release the instances created in the first pass and then retain the newly created one. If the first instances has not been retained by another object, it will deallocate.

TechZen