Nathaly
Nathaly

Reputation: 83

iOS - pushViewController pushes to a nil view controller

I am trying to make a UITableViewCell upon select lead to another viewController while carrying data to it. However, it just ends up pushing to a nil view controller

In Main.storyboard, I have created the view controller and have given it the class "DetailedTweetViewController"

http://postimg.org/image/hf7wg0ilp/ - image showing the classes and identifier

http://postimg.org/image/f0w0ezjzv/ - image showing no segues

Everything seems to be hooked up fine and all, this is my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSDictionary *currentTweet = _userPosts[indexPath.row];

    DetailedTweetViewController *tweetDetailedViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailedTweetStoryboard"];

    tweetDetailedViewController.statusID = currentTweet[@"id"];

    [self.navigationController pushViewController:tweetDetailedViewController animated:YES];


}

I have no clue why it's not working...

This is an image of the error: http://postimg.org/image/cjb595s8j/

UPDATE

I tried pushing directly to the view controller without passing data:

DetailedTweetViewController *detailedViewController = [[DetailedTweetViewController alloc]init];

[self.navigationController pushViewController:detailedViewController animated:YES];

But i didn't get any error just a blank screen: http://postimg.org/image/7i02wst9v/

UPDATE

Initialized the current view controller that has didSelectRowAtIndexPath in another viewController called viewController

this is the code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    FeedViewController *feedViewController = [[FeedViewController alloc]init];

    feedViewController.currentUserAccount = [_twitterAccounts objectAtIndex:indexPath.row];

    feedViewController.navigationItem.hidesBackButton = YES;

    [self.navigationController pushViewController:feedViewController animated:YES];

}

Upvotes: 1

Views: 851

Answers (2)

Hani Ibrahim
Hani Ibrahim

Reputation: 1449

You will need to initialize the 'feedViewController' from the storyboard also

You can't use self.storyboard to initialize a viewController unless the view you called the self.storyboard on is also already initialized from a storyboard.

For example To initialize the detailedTweetViewController from feedViewController through storyboard ... Then the feedViewController must be also already initialized from storyboard as well

Upvotes: 0

Aditya Deshmane
Aditya Deshmane

Reputation: 4722

Get storyboard like this instead of self.storyboard

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];// Find name of storyboard in your project plist

 DetailedTweetViewController *tweetDetailedViewController = [storyboard  instantiateViewControllerWithIdentifier:@"DetailedTweetStoryboard"];

Upvotes: 4

Related Questions