Segue, but not pressing / UITabBarController / UITableViewController when clicking on a cell

There should be a simple solution, but after 4 hours of viewing StackExchange, I refuse and try to answer this question here:

Situation: iOS 5, Xcode 4.2.1 using storyboards

Setup:

  • Root Navigation Controller = UITabBarController with 5 Elements
  • Each tab refers to a UITableViewController (via segues), which works fine, automatically
  • I have classes for each view controller and navigation controller (UITabBarController)
  • I click on the tab, say “Program”, and show me a list of elements (in the linked UITableViewController), for example, one of these elements is “Sessions”
  • I click Sessions, didSelectRowAtIndexPath is called just fine.
  • Now I want to execute a segue (which I connected from this UITableViewController, not the cell, to the new UITableViewController and gave it an identifier.
  • I'm calling: [self performSegueWithIdentifier:@"programToSessions" sender:self];

  • prepareForSegue is called, but then nothing. No errors, no warnings. New UITableViewController is not displayed.

  • Note: it appears, however, if I switch segue to "modal", but it drops / hides the original tab bar at the bottom (not intended ...)

So far, my problem seems to have had a likely solution. Navigation controller I figured that if I set up a link to the navigation manager in AppDelegate, it initiates / sets it as soon as the actual root navigation controller (in viewDidLoad) loads, i.e. something is mostly used line by line: app.navController = self.navigationController in viewDidLoad - this can work! Right? So, I changed the action of segue: [app.navController performSegueWithIdentifier:@"programToSessions" sender:self];

But nothing changes, it does not appear.

Any ideas?

It is decided:

There were a few problems. The main problem was that I missed the “navigation controller” between the UITabBarController and the UITableViewController. This can be done by adding a new “navigation controller” to the storyboard, then drag and drop from the UITabBarController (rootViewController) to this new controller and set RELATIONSHIP. Then drag RELATIONHIP into the UITableViewController. So, as indicated by the correct answer, it should look like this: UITabBarController → (relation) → UINavigationController → (relation) → UITableViewController

To load new UITableViewControllers on top of the last UITableViewController, just go and call it through the code. The final tree will look like this:

UITabBarController → (relation) → UINavigationController → (relation) → UITableViewController → (segue) → UITableViewController

Give segue id. In code use this:

  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"loadMyDetailView" sender:self]; } 
+4
source share
2 answers

You should use prepareForSegue:sender: to run the equivalent of didSelectRowAtIndexPath: (Free the last one.) Instead of pushing the new view controller in the navigation stack, segue already has a destinationViewController property that will work automatically. You can change this property if you want to configure a new view controller. Make sure segue.identifier correct!

Also, from your question, I notice some confusion regarding view controller controllers. You mentioned two of them: the tab bar controller and the navigation controller. In the storyboard, the setting should be like this:

 TabBarController --(relationship)--> NavigationController --(relationship)--> ViewController --(segue)--> next ViewController 

Make sure all of this is correct in the storyboard and see if it works.

+3
source

You do not need to program performSegue programmatically. You can create a segue from the first UITableViewController to the second in the storyboard by dragging the control from the UITableViewCell of the first UITableViewController to the second UITableViewController. If segue fails, its most likely reason is that the cell identifier in the method

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

and in the "Attributes Inspector" do not match.

To transfer data from the first UITableViewController to the second, add the following method to the first:

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"loadMyDetailView"]) { MyDetailViewController *detailVC = [segue destinationViewController]; NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow]; detailVC.dataToPass = [self getDataToPass:selectedRowIndex.row]; } } 
+1
source

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


All Articles