I’m using a NavigationViewController and 2 View Controllers (named ViewController and ResultViewController), to make a simple app, that will sum 2 textFields in the first ViewController and display the result in a label, in the ResultViewController. I’m using a push segue to connect the VCs, but I can’t create a variable that receives the sum from the textFields. The error says: “property sum not found on object of type ‘ViewController’ “. I also tried to create the sum variable inside the prepareForSegue method, without success…
Below, my first ViewController.m code snippet:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
}
- (IBAction)addButtonPressed:(UIButton *)sender {
ResultViewController *tempView = [self.storyboard instantiateViewControllerWithIdentifier:@"ResultViewController"];
double sum = [_fieldOne.text doubleValue] + [_fieldTwo.text doubleValue];
tempView.answer = self.sum.text; //here appears the error I mentioned
[self presentViewController:tempView animated:YES completion:nil];
}
The ResultViewController.m snippet:
- (void)viewDidLoad
{
[super viewDidLoad];
self.displaySum.text = self.answer;
}
Any help will be really appreciated! Thanks in advance!!
Sum is a local variable. You want