views:

19

answers:

1

I have an navigation-based app with three view controllers. The first has categories of information, the second has a list of items from that category and the third has detail on a specific item.

I populate view controllers 1 and 2 using an NSXMLParser which gets called on viewWillAppear. In the forward (VC1 to VC2 to VC3) direction, everything is fine, the parser gets called and the views are populated.

Unfortunately when the user chooses the back button on the navigation bar, the same process happens in reverse (VC3 to VC2 to VC1) as viewWillAppear is called again and so the parser is also called, even though it just fetches the same data.

I want to ensure that the parser is only called in the forward direction. Any ideas how I might structure this?

Thanks, Phil

+1  A: 

Could you do something as simple as having a BOOL ivar called goingForward on VC2 that gets set to YES by VC1 prior to -pushViewController:animated: call and set to NO by VC3 prior to -popViewControllerAnimated: ... and then check goingForward in VC2's -viewWillAppear?

I am sure that there are more elegant ways of doing this (and look forward to reading about them) - but this should work, don't you think?

westsider
Elegant or not, it sounds like a good solution to me. I think a pair of ivars will do it. I can use the viewWillAppear to check an ivar and decide whether to run the parser and use the viewWillDisappear to set the ivar accordingly. Thanks.
Phil John