Domanda

I'm new to iOS development. I have an app that has a UINavigationController (with an embedded UITableViewController, call it TableView1) and I need to display another UITableView (TableView2) on the tap of a UITableViewCell for TableView1.

I did some online searching and didn't really find anything super useful, but what I was able to find said that I have to present TableView2 instead of pushing it. Everything is working correctly, except that TableView2 doesn't have a back button and I have to create my own UIBarButtonItem and assign to leftBarButtonItem of the navigationItem.

This is all fine, except for the fact that I can't help but feel like I'm doing it wrong. Is there any easier way (or a more correct way) to accomplish what I'm trying to accomplish?

Code for TableView1

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewController *tableViewController = [[UITableViewController alloc] init];

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tableViewController];

    [self.navigationController presentViewController:navigationController
                                            animated:YES
                                          completion:nil];
}

EDIT: Along with this question, if I find out I'm doing this the correct way, how do I get the normal back button to display? or can I?

È stato utile?

Soluzione

Present it directly from that view controller:

[self presentViewController:navigationController animated:YES completion:nil];

Or use pushViewController:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewController *tableViewController = [[UITableViewController alloc] init];

    [self.navigationController pushViewController:tableViewController animated:YES];
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top