1

I've a nib file in which i added 2 views. Now, i want to initate(init) my second view in my code, because i show it again and again after initate. so when i try to load nib file like:

UINib *nib = [UINib nibWithNibName:@"Taxi_Login_View" bundle:nil];
NSArray *nibArray = [nib instantiateWithOwner:self options:nil];
UIView *alert = [nibArray objectAtIndex: 1];

I get second view successfully after initate. But my first view also initate that i don't want. I just want to initate second view not first. Now what i do for this.

Ali Raza
  • 1,183
  • 1
  • 10
  • 15

1 Answers1

1

The instantiateWithOwner: will call the initWithCoder: of all view in the nib file. Since you are instantiate a nib file not views with in your NIB file, all object declared in the NIB will be loaded.

If you do not want this then you will need to create separate nibs for both views.

rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • thanks for reply but how can i write initWithCoder please write some code line here and in initWithCoder can we get second nib file? – Ali Raza Nov 20 '13 at 12:53
  • Please explain your self? The `initWithCoder:` is the `init` of fro your views. It has nothing to do with your problem. You have 2 views in one NIB but you only want to load one. The you should not have them in one NIB. Since if a NIB gets load it will instantiate all object declared in that NIB. – rckoenes Nov 20 '13 at 12:58