Cauca
Cauca

Reputation: 402

Storyboard with Xcode 4.5

Folks, I Need help about Storyboard. I have a Storyboard with a Table and a View, I want to click in a cell and do a transaction to a view. I set DetalheMeuPostoAmigo to View and call it in didSelectRowAtIndexPath as code bellow.

When I run aplication I don't receive any error, but the transaction don't function too. I tested with alert and did OK. I reviewed the code many many times...

 Top10.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{   
   UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];   
   DetalheMeuPostoAmigo *detalhesMeuPostoAmigoVC = [storyboard instantiateViewControllerWithIdentifier:@"DetalheMeuPostoAmigo"];
   [self.navigationController pushViewController:detalhesMeuPostoAmigoVC animated:YES];
}

Link to Storyboard Image

Upvotes: 0

Views: 946

Answers (5)

Eric
Eric

Reputation: 7877

Your initial ViewController is not in a NavigationController.

On your storyboard select the TableViewController and from the menu select

Editor -> Embed In -> Navigation Controller

enter image description here

Upvotes: 1

Cauca
Cauca

Reputation: 402

Thanks for all answers, I tested all options but didn't have success, below the Sérgio's test

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

        DetalheMeuPostoAmigo *detalhesMeuPostoAmigoVC = [storyboard instantiateViewControllerWithIdentifier:@"DetalheMeuPostoAmigo"];


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

    if (detalhesMeuPostoAmigoVC == nil) {
        NSLog(@"Is null?"); // Here is not Null

    }
    if (self.navigationController == nil) {
        NSLog(@"Is null?"); // Here is Null

    }

Upvotes: 0

Paresh Masani
Paresh Masani

Reputation: 7504

Why don't you just have Segue created on the table cell? Select table cell, press control key and drag arrow to your view controller and select push. Give identifier to the Segue and you are done!

The problem with your code is you don't have UITableview embaded in UINavigationController. Embed it by selecting "Editor -> Embed In -> Navigation Controller". Then your code should work.

FYI this articles on storyboards are awesome!

Upvotes: 1

I don't know the answer. But i had similar problems in the past. Check if self.navigationController == null if it's null here is your problem.

Boa sorte

Upvotes: 1

Romo
Romo

Reputation: 222

I am not an expert on this, but try using the existing VC:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{    
   UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];    
   YOURCURRENTVC *detalhesMeuPostoAmigoVC = [storyboard instantiateViewControllerWithIdentifier:@"DetalheMeuPostoAmigo"]; 
   [self.navigationController pushViewController:detalhesMeuPostoAmigoVC animated:YES]; 
} 

Upvotes: 2

Related Questions