Greg
Greg

Reputation: 1296

Adding detail view to UITableView

This app is my first app using a UITableView, and I've run into issues why trying to add a detail view to it. (because I made my app a "View-based Application" when I first created it, I have to do this manually).

This is the code for my didSelectRowAtIndexPath: of the table view:

detail = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle: [NSBundle mainBundle]];
detail.delegate = self;
detail.dtitle = [titles objectAtIndex: indexPath.row];
detail.dusername = [usernames objectAtIndex: indexPath.row];
detail.dpassword = [passwords objectAtIndex: indexPath.row];

[self.navigationController pushViewController: detail animated:YES];
//[self presentViewController:detail animated:NO completion:nil];

The second to last line is the one causing problems. I copied it from a blank "Master-Detail Application" that I made, but it doesn't seem to work in this app as it does in the other. The commented out line is what I've been using in it's place, but isn't exactly what I want.

What can I do to fix this?


Secondly, in theDetailViewController, the back button in my title bar (the navigation item of a navigation bar, to be precise) just will not appear. Is there code I have to add to indicate that this view is a subordinate view or something?

Upvotes: 0

Views: 1004

Answers (1)

rmaddy
rmaddy

Reputation: 318804

In order to push another view controller using the nav controller, there actually needs to be a navigation controller. Is "self" in a navigation controller?

If not, create a navigation controller setting its root view controller to the first view controller. If the first view controller is your app's root view controller, now make the navigation controller the root view controller instead.

Once that is in place you can call [self.navigationController pushViewController: detail animated:YES];.

Upvotes: 1

Related Questions