views:

242

answers:

3

Hi,

could anyone help me with the next question. I am working on an app with the navigation similar to Notes app has. The problem I faced i how to implement navigation within one level and keep root view as the previous screen. So the scenario I need to achieve: 1. Drill down from the top level list to the detailed view. 2. From this detailed view navigate to the detailed view of the next/previous item. 3. Back button should lead to the root view.

I've tried several approaches and no-one worked fine for me. The most right solution from my point of view is to create a middle controller between the root and detailed controllers to handle this next/prev redirects. But the main problem here is that switching from one detailed view to another the navigation pane stays the same, so it's not involved in the animation, whether Notes app work right in this case.

Could you point me how it' better to arrange controllers interaction in this case?

Thanks in advance. Sorry for quite big post, was trying to be as informative as possible.

Best regards, Roman

+1  A: 

I think the best implementation is this way:

Say you have a Note class where the data is stored.

You could have two view controllers, one with the list of notes and one with the details. Both of these can be added to a navigation controller. Then, when you want to switch to the next note, you retrieve that object somehow and assign it to your detail controller with a -setNote: call. That method will be responsible for changing what the outlets are displaying.

Jongsma
Thanks for the reply! I considered this way, but I am not sure is it possible to add animation to simulate the navigation to another view?
Do you mean animating the transition when the next/previous button is pressed? Why not make a new subview and animate that into view (and the old one out). If that's not what you mean, please clarify.
Jongsma
A: 

Yeah, it's misbehaving badly. Jongsma's reply is the best. In case you wanted to re-create controllers, I've found this to work:

[parent performSelectorOnMainThread:@selector(showMyItem:)
                         withObject:myNextItem 
                      waitUntilDone:NO];
[self.navigationController popViewControllerAnimated:NO];

performSelectorOnMainThread delays execution of method until next run of main loop, and by then previous controller is removed already and navigation controller is in stable state.

porneL
A: 

I've resolved this question - it's enough to pop current view and push new one, created for the next object in the list. The only think to remember is to save the reference to the navigation controller before the pop call, because after it self.navigationController becomes nil.