IOS navigate to new view but get a black screen - ios

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

Related

Cant navigate to other Viewcontrollers from a commonViewController's tableview click

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];

While pushing a viewcontroller there is a jerk in animation

For pushing a view controller I'm using following code. On tap of UITableViewCell need to push DetailViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row)
{
NSDate *object = self.objects[indexPath.row];
DetailViewController *controller = [DetailViewController new];
[self.navigationController pushViewController:controller animated:YES];
}
}
Now problem is I get a jerk while animating. Refer to screenshot
its because of transparency. just set a background color for your viewcontroller. thats all.
Most probably you're doing something "heavy" on the main thread, while loading DetailViewController.
Could you show us what are you doing in DetailViewController?
I think there is issue with allocating object and pushing same object.
Do the following changes, it will work fine.
Your code :
DetailViewController *controller = [DetailViewController new];
[self.navigationController pushViewController:controller animated:YES];
Replace :
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
MyViewController *controller = (MyViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"<your Storyboard ID>"];
it will work fine at my end.
Hope this help you.

how to pass data to subview controller in ios app from the calling method didSelectRowAtIndexPath

Could somebody explain me what i'm doing wrong in the code below?
I try to pass data from the didSelectRowAtIndexPath method but in the SizeViewController productKey has still value of null
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
SizeViewController *sizeViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"SizeView"];
sizeViewController.title = [self.choosedProducts objectAtIndex:indexPath.row];
sizeViewController.productKey = [self.choosedProductsIds objectAtIndex:indexPath.row];
[[self navigationController]pushViewController:sizeViewController animated:YES];
}
Can u try to get a reference to the storyboard instead of using the self.storyboard property? It is just a guess.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
Also, can u verify in your solution that sizeViewController is not nil?
You are trying to load a view controller from storyboard,So it should be initialised as
SizeViewController* detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"SizeViewController storyboard identifier"];

Application tried to push a nil view controller on target

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]];

Cannot load viewController using MFSidemenu

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.

Resources