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

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.