I have a viewController, lets say blaVC, which calls another view controller blubbVC through a button press. As there are 4 buttons, all calling blubbVC with the same nib, but the content should vary according to which button was pressed in blaVC (content will be loaded from a plist), I’d need blubbVC to know “I’ve been called, because button A was pressed, so I’ll load from the plist with objectForKey:@”button A”” (so to speak..).
I call blubbVC like that
- (IBAction) buttonA:(id)sender {
blubbVC *detailView = [[blubbVC alloc] initWithNibName:@"blubbNib" bundle:nil];
[self.navigationController pushViewController:detailView animated:YES];
[detailView release];
}
I tried to pass sender, but as I load the content in initWithNibName, sender comes to late, the content was already loaded (or tried to) and my view stays empty. How would I do that?
Thank you!
You should define a function that says takes the sender (or some value representing which button was pressed) that sets up all the state, after it’s been initialized.
For example:
When you init the view controller, it’s not yet displayed. Before you call pushViewController, call the new function, so you’d have:
If it’s true that this is too late (you need the data in ‘initWithNibName’), then either define your own
-[initWithNibName: andSender:]or something similar, and calls[super initWithNibName:]before setting up the rest of the state.