I got the below error:
Application tried to push a nil view controller on target UINavigationController: 0x7b98940.
It is caused when I 'click' a cell of an UITableViewController.
Code:
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
VerifyInfoViewController *verifyInfoVC = [self.storyboard instantiateViewControllerWithIdentifier:#"verifyInfoVC"];
[self.navigationController pushViewController:verifyInfoVC animated:YES];
}
This error means your ViewController has not been allocated properly, and i guess self.storyboard is nil, If yes this means you didn't initialise your master viewController and you can do the below trick:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
Related
I have to push a detail view controller when I tap on a tableview cell using with storyboard identifier. I have already designed the view controller. Now i have to navigate to the designed screen by tapping table view cell in the left menu. I am using LGSideMenuController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
if (indexPath.row == 0) {
ProfileViewController *profileVC = (ProfileViewController*)[mainStoryboard instantiateViewControllerWithIdentifier:PCProfileVC];
[self.leftMenuVC navigateToViewController:#"profileVC"];
}}
-(void)navigateToViewController:(UIViewController*)viewController{
[(UINavigationController *)[self sideMenuController].rootViewController pushViewController:viewController animated:YES];
[[self sideMenuController] hideLeftViewAnimated:YES completionHandler:nil];}
Please help me to do. Thanks
Why are you pushing viewController in rootViewController.
If this code snippet is written in your ViewController.m, then try replacing,
[(UINavigationController *)[self sideMenuController].rootViewController pushViewController:viewController animated:YES];
with
[[self sideMenuController].rootViewController.navigationController pushViewController:viewController animated:YES];
If your identifier PCProfileVC is correct, then this code should work.
Kindly see this link for information on pushing ViewController in UINavigationController.
Try this code :
YourViewControllerClass *viewController = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:#"ViewController"];
// instanciate your viewcontroller
[(UINavigationController *)[self sideMenuController].rootViewController pushViewController:viewController animated:YES]; //push your viewcontroller
[[self sideMenuController] hideRightViewAnimated:YES completionHandler:nil]; //hide the menu
I have navigate to a new class with view by the below table view delegate method but I get a black screen returned.
#import "NewClass.h"
- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName: #"MainStoryboard" bundle: [NSBundle mainBundle]];
NewClass *new = [storyboard instantiateViewControllerWithIdentifier: #"newDetail"];
new.array = localArray;
[self presentViewController: new animated: YES completion: nil];
}
I have NSLog the array on the new class there and the data is received in the new class, all the storyboard name, identifier tag are correct placed, but I don't know why I still getting a black screen, could anyone help me point out what is the error cause there?
try this code:
- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
NewClass * new = [storyboard instantiateViewControllerWithIdentifier:#"newDetail"];
new.array = localArray;
[self.navigationController pushViewController:new animated:YES];
}
It should be,
ViewController *new = [storyboard instantiateViewControllerWithIdentifier: #"newDetail"];
And make sure the id of your view controller is set to newDetail on storyboard
I have a commonViewController to pop up on other viewcontrollers and the commonViewController has a view and a tableview inside it and also some other components. I have populated that view successfully on other viewcontroller pages, but the problem is; when iam trying to navigate to some other viewcontroller pages while iam clicking the rows in commonViewController's tableview.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 1)
{
EditProfileViewController *nextViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"EPVController"];
[self.navigationController pushViewController:nextViewController animated:YES];
}
}
I have tried both presentViewController and pushViewController but it is not navigating anywhere. What is the issue. Please help me.
Get reference to your storyboard and load viewcontroller using identifier:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"YourStoryboardName" bundle:nil];
EditProfileViewController *nextViewController = [storyboard instantiateViewControllerWithIdentifier:#"EPVController"];
[self.navigationController pushViewController:nextViewController animated:YES];
I am new in iOS programing and I have an issue. I have a customized table view cell with disclosure indicator in a separate xib file and I want to call a viewcontroller which is in storyboard when the user taps the cell.
Here is the customized table view cell :
Here are the table view (class : TableViewController) that displays the custom table cell and the view (class : ViewController) I want to call when the user taps the customized table view cell :
Does the view I want to call have to be in a separate xib file or can I let it in my storyboard? What is the best solution?
Just use didSelectRoWAtIndexPath method of table view …DO something like this..
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
NSString* viewType = #"YourVCIdentifier";//u can have ContactVC or NavC as other options depending on ur condition
UIViewController* viewController = [storyboard instantiateViewControllerWithIdentifier:viewType];
[self.navigationController pushViewController:viewController animated:YES];
}
that will do it
Use the UITableViewDelegate method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
and push the view controller manually.
Assign a storyboard ID to the view controller in the storyboard, and then do something like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil];
UIViewController *destVC = [storyboard instantiateViewControllerWithIdentifier:#"your_view_controller_storyboard_ID"];
[self.navigationController pushViewController:destVC animated:YES];
}
This is where you assign a storyboard ID to your view controller:
And don't forget to set your view controller as your tableView delegate :)
I am building an app using storyboard. I am using the MFSidemenu library for creating a sidemenu like facebook app. the side menu appears properly but when i tap a cell on the side menu, the menu doesnt go away and it doesnt load another view controller. Please note that i am using storyboard.
Thank you.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
AlbumsTableVIewController *AlbumsViewController = [storyboard instantiateViewControllerWithIdentifier:#"Albums"];
AlbumsViewController.title=[NSString stringWithFormat:#"Demo Controller #%d-%d", indexPath.section, indexPath.row];
NSArray *controllers = [NSArray arrayWithObject:AlbumsViewController];
self.sideMenu.navigationController.viewControllers = controllers;
[self.sideMenu setMenuState:MFSideMenuStateClosed];
}
you have to implement delegate method to your MainMenu Controller, because if u place your code like above, it will change your sideMenu not ur MainMenu. i am working with storyboard here. this is my code on my MainMenuController
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
UINavigationController *navigationController = (UINavigationController *)self.navigationController;
UIViewController *leftSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:#"leftSideMenuViewController"];
UITableViewController *SideMenu=(UITableViewController *)leftSideMenuViewController;
SideMenu.delegate=self; //here is the delegate
[MFSideMenu menuWithNavigationController:navigationController
leftSideMenuController:SideMenu
rightSideMenuController:nil];
so you need to hook up with your viewController from here, navigating thru delegate pattern.