patternMinor
Segue between view controllers using NIB files
Viewed 0 times
seguecontrollersviewbetweenfilesusingnib
Problem
I'm learning how to develop for iOS and I want to begin with nib's before storyboard to get a better understanding.
I just set up 3 view controllers:
-
-
-
The HomeVIewController.h:
The HomeVIewController.m:
This view controller has a nib file with a view and 3 buttons at the bottom of the page that I use to navigate.
The StackTableViewController.h:
```
#i
I just set up 3 view controllers:
-
HomeVIewController-
StackTableViewController-
CreateViewControllerThe HomeVIewController.h:
#import
@interface HomeViewController : UIViewController
- (IBAction)goToStack:(id)sender;
- (IBAction)goToCreate:(id)sender;
@endThe HomeVIewController.m:
#import "HomeViewController.h"
#import "StackTableViewController.h"
#import "CreateViewController.h"
@interface HomeViewController ()
@property (strong, nonatomic) UINavigationController *navigationController;
@end
@implementation HomeViewController
- (id)init {
self = [super initWithNibName:@"HomeViewController" bundle:nil];
if (self) {
// Do something
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)goToStack:(id)sender {
StackTableViewController *stackViewController = [[StackTableViewController alloc] initWithNibName:@"StackTableViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:stackViewController];
[self presentViewController:self.navigationController animated:YES completion:nil];
}
- (IBAction)goToCreate:(id)sender {
CreateViewController *createViewController = [[CreateViewController alloc]initWithNibName:@"CreateViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc]initWithRootViewController:createViewController];
[self presentViewController:self.navigationController animated:YES completion:nil];
}This view controller has a nib file with a view and 3 buttons at the bottom of the page that I use to navigate.
The StackTableViewController.h:
```
#i
Solution
Your code is fine. I understand that it feels strange to instantiate
You actually don't need to keep a reference to this navigation controller in your
UINvagationController where you only need custom view controller, but this is how it's done in UIKit. You actually don't need to keep a reference to this navigation controller in your
HomeViewController. You better keep reference to StackTable and Create view controllers.Context
StackExchange Code Review Q#73512, answer score: 2
Revisions (0)
No revisions yet.