Navigation Controller not Pushing/Popping View Controllers

Posted by senfo on Stack Overflow See other posts from Stack Overflow or by senfo
Published on 2010-05-06T14:31:26Z Indexed on 2010/05/06 16:58 UTC
Read the original article Hit count: 217

Filed under:
|

I'm working on a view-based iPhone app that has the following flow:

search -> (list | map) -> details

To accomplish the transitions between views, I have a UINavigationController, with the search view controller being the root. After a user performs a search, I transition to a view with a segmented control, which acts as a tab to switch between the list and map functionality (per a suggestion from a related question I had). This view contains a UIViewController, which allows me to switch between the list/map view when a user taps the segmented control. I'm fine up until this point.

As you can see from the above mentioned flow, I would like to provide the ability to transition into a details view. Each row of my table in the list view contains a details disclosure button for allowing the user to drill down into a details view. The problem is, when I try to push the details view onto the navigation stack, nothing happens.

Below is the delegate method (from my list view controller) to handle the details disclosure button being tapped. I've set up break points, so I know the code is running. The navigation controller simply doesn't want to push the detailsController onto the stack (my guess is that I don't have a pointer to the correct UINavigationController).

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
 if (detailController == nil)
 {
  detailController = [[DetailsViewController alloc] init];
 }

 [self.navigationController pushViewController:detailController animated:YES];
}

Assuming I was probably missing a pointer to the navigation controller, I exposed a UINavigation property on my list and map views (navigationController is readonly) and initialized them with a pointer to the navigation controller from my SwitchViewController (the view responsible for switching between list/map views when a user changes the value of the segmented control). Unfortunately, this did not solve the problem.

Am I on the right track? If so, how do I see to it that my view has a pointer to the correct navigation controller? Should I add a delegate, which allows me to call a function in the SwitchViewController that transitions into the details view (this seems messy)?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about cocoa-touch