I am creating a Rock Paper Scissors game in Objective-C and currently I'm having an issue with bringing an integer from one View Controller to another.
I am using the utility application template and I am using the FlipsideViewController as an area to set the rounds in the best (Best out of 3, 5, 7, etc.). However, I am unable to bring that integer back to the MainViewController to put it in to use. I read through the other questions on this topic but couldn't get it to work.
Here is the protocol in the FlipSideViewController.h file
@class FlipsideViewController;
@protocol FlipsideViewControllerDelegate
- (void)addItemViewController: (FlipsideViewController *)controller didFinishEnteringItem: (int)rounds;
@end
Here is the action that occurs when the button is pressed to finalize the amount of rounds
- (IBAction)submitBOO:(id)sender {
int rounds = 0;
rounds = _textField.text.intValue;
if (rounds % 2 ==0){
_labelBOO.text = @"Pick an odd number!";
}
else
[self.delegate addItemViewController:self didFinishEnteringItem:rounds];
}
The button in MainViewController.m that switches to FlipsideViewController
- (IBAction)beginGame:(id)sender {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}