Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open view controller from didSelectRowAtIndexPath within storyboard?

I have a storyboard with tabbarcontroller. One of tab bar has a tableview and I want that when the user tap in a row from tableview open a detail view. The problem is when I open detail view tab bar and navigation bar hides... In the storyboard I create the detail view as a new view controller, then I create a new file and referred it to the class of detail view .

The code in didselectrowatindexpath:

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

detalleYouTube *dvController = [[detalleYouTube alloc] init];

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

}

Thank you in advance!

like image 646
jcamacho Avatar asked Jan 04 '12 09:01

jcamacho


2 Answers

This is kinda old but if someone needs to do this here's an easy approach:

You can use add a segue from the view in the tab bar to detalleYouTube, put an identifier to the segue and do this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath
{
[self performSegueWithIdentifier:@"segueIdentifier" sender:tableView];
}
like image 64
Esteban Avatar answered Oct 19 '22 12:10

Esteban


Another approach to this is not to use tableView:didSelectRowAtIndexPath but instead use prepareForSegue:sender

the way I did it was:

-(void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
{
    DetailViewController *viewController = [segue destinationViewController];
    CustomObject *custObject = [arrayOfObjects objectAtIndex:[self.tableView indexPathForSelectedRow].row];
    viewController.objectNeeded = custObject;
}

This example is based on the idea that your detail view controller is connected to your table view controller.

like image 26
SolThoth Avatar answered Oct 19 '22 11:10

SolThoth