I'm trying to create push and modal segues the right way, and from what I understand is to embed my root view controller in a navigation controller in my app delegate...So when I want to create segues they all will be modal/pushed to the same stack..is that right?
I'm really trying to understand this since i'm having some issues doing it correctly.
I want to be able to perform :
FirstViewController > click on a button (modal segue) > SecondViewController > click on a button (push) > ThirdViewController
And from the ThirdViewController I will click on cancel take the ThirdViewController of the stack and get to the SecondViewController click cancel take SecondViewController of the stack and get to the FirstViewController which is my rootviewcontroller and it will be the only view controller in the viewstack...
isn't it how it's suppose to work? please correct me if I'm wrong.
This is how I did it so far: (I know how to dismiss view controllers so I did not add this code)
AppDelegate.h:
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "FirstViewController"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationController;
@property (strong, nonatomic) FirstViewController *firstViewController;
@end
AppDelegate.m:
@implementation AppDelegate
@synthesize firstViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
firstViewController = [[FirstViewController alloc]init];
self.navigationController = [[UINavigationController alloc]initWithRootViewController: firstViewController];
[self.window setRootViewController:self.navigationController];
[self.window makeKeyAndVisible];
return YES;
}
FirstViewController.h:
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@interface HomeViewController : UIViewController
- (IBAction)goToSecond:(id)sender;
@end
FirstViewController.m:
@interface FirstViewController ()
@end
@implementation FirstViewController
- (id)init {
self = [super initWithNibName:@"FirstViewController" bundle:nil];
if (self) {
// Do something
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (IBAction)goToSecond:(id)sender {
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController presentViewController: secondViewController animated:YES completion:nil];
}
Now in the second ViewController I'm trying to think how to get to the rood navigation controller so I can add to it another screen instead of creating another navigation controller in SecondViewController.