In the following setup, Button 1
calls First VC
and Button 2
calls Second VC
Currently, I use the following code to call SecondVC
by tapping Button 2
.
MainVC.m
@implementation MainVC()
....
UINavigationController *navController = [self.childViewControllers objectAtIndex:0];
SecondVC *secondVC = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];
[navController pushViewController:secondVC animated:YES];
The code above displays SecondVC
just fine. However, in the First VC
there are statements that need be executed before "Second VC" is presented, that are being skipped!
I execute these statements in First VC
inside -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
. When the Next
Button is tapped in the First VC
, all the statements execute because it triggers prepareForSegue
before presenting SecondVC
. This step is skipped when the code above is used.
Extra Info:
A) Though a Navigation Controller
, Main VC
in my app does not show the navigation bar in my app. I believe this would be against HIG to display two navigation bars on an iPhone. I show it here to identify Main VC.
B) There are textFields in FirstVC that User fills out. If I just copy the code, will it read and save the data from textFields.text?
Question: How can I call prepareForSegue
from First VC
when Button 2
is tapped in MainVC
? or is there another approach to this?