0

I have a noob-question, that might be similar to Dynamically create multiple instances of a UIView from a NIB but I'm missing the big picture.

I've got a class with NIB, called UserViewController and I need to create multiple instances, based on the number of users, store them in an array and be able to modally navigate between them.

A class with NIB, called SelectNumberOfUsersViewController contains this IBACTION-code:

users = [[NSMutableArray alloc] init];
for (int i=0; i<numberOfUsers; i++) {
    user = [[UserViewController alloc] init];
    user.userid = i+1;
    [user doInitialization];
    [users addObject:user];
} 

I see that the initWithNibName of the instance user is run, but how do I address and show the UI for the first user in the users array? I'm not sure if commands like

myView = [[[NSBundle mainBundle] loadNibNamed:@"XXX" owner:self options:nil] objectAtIndex:0];
[[self view] addSubview:searchDateView] 

should be used, since the array contains entire objects of the class User with NIB and everything - or...?

Community
  • 1
  • 1
Anders
  • 251
  • 3
  • 13

1 Answers1

0

If you want to initialise a viewcontroller with a nib file you should use:

user = [[UserViewController alloc] initWithNibName:@"NibName" bundle:nil];

If you want to push that view you could call:

[self.navigationController pushViewController:user animated:true];

To present it, call:

[self presentModalViewController:user animated:true];

If you just want to add the view to the current viewcontroller use:

[self.view addSubView:user.view];

But the sure to remove the previous one too.

I hope this was of any help.

Thomas
  • 649
  • 9
  • 17