How to open a view controller from didSelectRowAtIndexPath in a storyboard?

I have a storyboard using tabbarcontroller. There is a tabular view on one of the tab panels, and I want the user to open a detailed view by clicking on a row from the table. The problem is when I open the tab bar with the detailed view and the skins of the navigation bar ... In the storyboard, I create the detailed view as a new view controller, then create a new file and pass it to the detailed view class.

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!

+6
source share
3 answers

I assume that you have a Detail view as part of the storyboard (not in a separate XIB), if so, you will need to place a separate navigation controller at the beginning of the Details section of the TabBarItem.

This page has a good guide on what I think you are trying to achieve: http://maybelost.com/2011/10/tutorial-storyboard-in-xcode-4-2-with-navigation-controller-and- tabbar-controller-part1 /

Also check out these links for a more in-depth storyboard guide:

http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2

+3
source

This is kind of old, but if someone should do it here, it's easy:

You can use the addition of segue from the tab bar view in detalleYouTube, put the identifier in the segment and do this:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"segueIdentifier" sender:tableView]; } 
+6
source

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

how i did it:

 -(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 a detail view controller is connected to a table view controller.

+5
source

Source: https://habr.com/ru/post/905073/


All Articles