UITableView didSelectRowAtIndexPath with prepareForSegue, but didLoadView not called

I am learning iOS and I wrote a simple iPhone application using iOS 5. The application displays a UITableView populated with speaker names when I select one of the names that is supposed to be sent to the UIViewController and show details about that person (name, address etc.), so actually two ViewControllers have a UITableViewController and a UIViewController (both subclasses).

So, in MICSpeakersTableViewController: UITableViewController I have this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { MICSpeakerDetailViewController *detailViewController = [[MICSpeakerDetailViewController alloc] initWithNibName:@"Detail" bundle:nil]; [detailViewController setSpeaker:[[self getSpeakers] objectAtIndex:indexPath.row]]; [self.navigationController pushViewController:detailViewController animated:YES]; } 

which is called when I select it, and the loudspeaker fills (in that it does not match the nil and description).

Then I have this in the same implementation:

 - (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { NSIndexPath *indexPath = [ self.tableView indexPathForCell:sender]; if ([segue.identifier isEqualToString:@"Detail"]) [segue.destinationViewController setSpeaker:[[self getSpeakers] objectAtIndex:indexPath.row]]; } 

Which is also called, and the segue.identifier parameter is Detail, and the destinationViewController speaker is set correctly (non-zero, description matches). I'm not quite sure why I should install this again, since I install it in didSelectRowAtIndexPath, but I install it again and it seems harmless.

Finally, initWithNibName and self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil] are called in MICSpeakerDetailViewController; returns an instance.

However, segue never happens, and viewDidLoad is never called.

Most likely something small, but I can't figure it out ... any advice?

Edit: here is a screenshot of the storyboard showing segue and controllers:

enter image description here

+4
source share
1 answer

You need to embed the view controllers in the navigation controller for push segues to work. I do not know why this allows you to define them without it.

To do this, click on the table view controller, then select "Editor → Embed in → Navigation Controller". If you also need to be in the controller of the tab bar, then the navigation controller is built into it in the same way. You should see the following:

enter image description here

Now your session will work.

+6
source

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


All Articles