I am transferring data from FirstView to SecondView after clicking on a button.
FirstView.h
@property (strong, nonatomic) NSString *stringOfFirstView;
FirstView.m - (void)pushToSecond { SecondView *controller = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil]; controller.stringOfSecondView = self.stringOfFirstView; [self.navigationController pushViewController:controller animated:NO]; }
In SecondView, I have
SecondView.h
@property (strong, nonatomic) NSString *stringOfSecondView;
At SecondView,my goal is to go back to FirstView by clicking on back button and also want assign stringOfSecondView to stringOfFirstView as well
Question :
How can I assign stringOfSecondView to stringOfFirstView via clicking back button.
Just let you know, I am detecting an click event on back button in SecondView by doing
SecondView.m
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:YES];
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound)
NSLog(@"will show onto console");
}
But I am stuck how to do passing data back
Please advice if you have any clues about this issue.
I would use a delegate. So in your SecondView you need to create a protocol that sends data back to your FirstView. Your FirstView would become a delegate of the SecondView. There are tons of tutorials on how to make a delegate.