The title says most of what I'm looking for:
I have 2 buttons on my main menu that both call the same view controller. Depending on which button was clicked the view controller behaves a little differently. I thought I had the fix using NSNotificationCenter, but it won't catch anything the first time into the view controller (because it hasn't been loaded yet). Are there any other ways to do this?
EDIT: There seems to be some confusion, perhaps on my end. The problem is passing the information across multiple view controllers. The buttons in the Main Menu view controller CALL the second view controller, the problem is that second view controller not having any knowledge of any variables created in the Main Menu view controller.
You could add a variable to the class of the second view controller and set that variable to a value depending on which button was pressed when you initialize the second view controller:
- (IBAction) buttonPressed:(id)button
{
//Initialize your view controller
MyViewController* secondViewController = [[MyViewController alloc] init...];
//Assign a value to a variable you create (I called it pushedButtonValue) so the
//viewController knows which button was pressed
secondViewController.pushedButtonValue = [button tag];
//Transition to the new view controller
[self.navigationController pushViewController:secondViewController animated:YES];
}
The event handler for the button press will usually have an (id)sender parameter. Use this to determine which button was pressed based .
- (IBAction)pushButton:(id)sender {
UIButton *button = (UIButton *)sender;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With