Reputation: 313
Inside my TableView, I am pressing one of the cells to enter the detailed view, and for some reason it won't take me to the detailed view. Does anyone see a problem in the below code?
For context, this is a teacher directory, and pressing one of the cells brings up the teachers picture and other info.
Thanks for the help...if you need any more info I can add it in.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Get the selected teacher
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"Teachers"];
NSString *selectedTeacher = [array objectAtIndex:indexPath.row];
//Initialize the detail view controller and display it.
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
dvController.selectedTeacher = selectedTeacher;
[self.navigationController pushViewController:dvController animated:YES];
dvController = nil;
}
Upvotes: 0
Views: 826
Reputation: 81
I don't know if you ever resolved your problem, but I was having the same problem where my Detail View was not appearing. I finally replaced
[self.navigationController pushViewController:dvController animated:YES];
with
[self presentModalViewController:dvController animated:YES];
and it worked. Hope that helps.
Upvotes: 1
Reputation: 12366
You should check if dvController is correctly loaded, so try to NSLog dvController once you have called the alloc-init. Another way to instantiate it is to use this simple call which works if you created the view controller and the xib together:
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:nil bundle:nil];
Besides there is no reason to nil dvController at the end. If you're concerned with memory management, that is you don't want to leak dvController, simply autorelease it. So replace:
dvController=nil;
with:
[dvController autorelease];
this works because the navigation controller retains the pushed view controller (or use ARC).
Finally I assume the tableView:didSelectRowAtIndexPath: is called... if not sure, just a place a breakpoint.
Upvotes: 1