SettingsViewController *viewController = [[SettingsViewController alloc] init];
[[self navigationController] pushViewController:viewController animated:YES];
I solved this problem by custom initialisation of destination view controller.
Your destination view controller:
-(id) initWithSender:(UINavigationController*)sender
{
self=[sender.storyboard instantiateViewControllerWithIdentifier:@"DestinationVCIdentifier"];
if (self) {
//custom initialisation
}
return self;
}
And using it:
DestinationVC *viewController = [[SettingsViewController alloc] initWithSender:self.navigationController];
[[self navigationController] pushViewController:viewController animated:YES];
Try this:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
SettingsViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"setting"];
[self.navigationController pushViewController:viewController animated:YES];
Set the settingviewcontroller's identifier to "setting"
Hi You've to set the top bar property (navigation bar) to inferred for the view controller. In my case I previously set the top bar as "Translucent navigation bar"
Usually this happens you perform a segue from a modal view controller.
so you could initialise using the name of the xib or storyboard as everyone is suggesting and that’s valid.
Although if you’re using storyboards and your initial viewcontroller is on the storyboard, they maybe rather do the following,
// Method in your initial viewcontroller
- (void)youPushMethod {
// Name your segue on your storyboard, e.g. SegueIndentifier
[self performSegueWithIdentifier:@"SegueIndentifier" sender:self];
}
Then,
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@“SegueIndentifier"]) {
SettingsViewController *settingsViewController= segue.destinationViewController;
}
}
try this
SettingsViewController *viewController = [[SettingsViewController alloc]initWithNibName:@"SettingsViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:viewController animated:YES];
An easy way to do it is by instantiate with the storyboard. You must give your viewcontroller a Storyboard ID and then use the following code:
YourView *view = [self.storyboard instantiateViewControllerWithIdentifier:@"YourViewID"];
When this is done simply push:
[[self navigationController] pushViewController:view animated:YES];
Hope this helps.