I opened my project after a week and it seems, for all the new UIViewController
I create in the StoryBoard
, instantiateViewControllerWithIdentifier
is returning is nil. All the ViewControllers
which are already in the project are working fine.
GCHConnectViewController* gchCVC = [self.storyboard instantiateViewControllerWithIdentifier:@"GchConnect"];
navigationController.viewControllers = @[gchCVC];
First line is returning nil, my initial thought was that self.storyboard
is returning nil, so I tried this and put breakpoint.
if (self.storyboard != nil) {
GCHConnectViewController* gchCVC = [self.storyboard instantiateViewControllerWithIdentifier:@"GchConnect"];
navigationController.viewControllers = @[gchCVC];
}
and its going to inside the if and crash at the second line..
I've also added the class and storyboard
id correctly.
If I try to load another ViewController
which was already there, it works, but not new ones.
Can't seem to figure out what is the problem. Any help is appreciated.
EDIT:
full usage:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// Scroll to the top when tapped
NSIndexPath *ind = [NSIndexPath indexPathForRow:0 inSection:0];
[tableView scrollToRowAtIndexPath:ind atScrollPosition:UITableViewScrollPositionBottom animated:NO];
NavigationViewController *navigationController = (NavigationViewController *)self.mm_drawerController.centerViewController;
if (indexPath.section == 0) {
if (indexPath.row == 0) {
DailyCheckViewController *dailyCheckViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"dailyCheckViewController"];
navigationController.viewControllers = @[dailyCheckViewController];
}else if (indexPath.row == 1) {
ECGViewController *ecgViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ecgViewController"];
navigationController.viewControllers = @[ecgViewController];
}else if (indexPath.row == 2) {
SPO2ViewController *spo2ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"spo2ViewController"];
navigationController.viewControllers = @[spo2ViewController];
}else if (indexPath.row ==3) {
TempViewController *tempViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"tempViewController"];
navigationController.viewControllers = @[tempViewController];
}else if (indexPath.row == 4) {
SLMViewController *slmViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"slmViewController"];
navigationController.viewControllers = @[slmViewController];
}else if (![UserList instance].isSpotCheck && indexPath.row == 5) {
PedViewController *pedViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"pedViewController"];
navigationController.viewControllers = @[pedViewController];
}
}else if(indexPath.section == 1){
if (indexPath.row == 1) {
AboutCheckmeViewController* aboutCheckmeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"aboutCheckmeViewController"];
navigationController.viewControllers = @[aboutCheckmeViewController];
}else if (indexPath.row == 3) {
AboutViewController* aboutViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"aboutViewController"];
navigationController.viewControllers = @[aboutViewController];
}else if (indexPath.row == 2) {
SettingsViewController* settingsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"settingsViewController"];
navigationController.viewControllers = @[settingsViewController];
}else if (indexPath.row == 0) {
GCHConnectViewController* gchCVC = [self.storyboard instantiateViewControllerWithIdentifier:@"GchConnect"];
navigationController.viewControllers = @[gchCVC];
}
}
[self.mm_drawerController setCenterViewController:navigationController withCloseAnimation:YES completion:nil];
}
I've a navigation drawer. switching to other ViewController except with the one with identifier 'GchConnect' (ie. indexPath.section == 1 and indexpath.row == 0 ) works. They are all in the same storyboard
instead of
try to use:
What you should do is either push or present view controller. At the moment you're trying to replace all viewcontrollers that are in your navigationcontroller,
My problem was that I add localization and changes I add to the storyboard were getting updated to the simulator/device.
It fixed it by:
selecting the StoryBoard, then
Editor > Localization Locking > Reset Locking Controls
If you have multiple storyboards,
self.storyboard
returns the one that the currentUIViewController
is in. You need you check the name of storybaord for "GchConnect". And instantiate that storyboard with storyboardWithName:bundle:use this code
Try this code,
if you present the
viewcontroller
use below code,or if you Push the
viewcontroller
use below code,hope its helpful