Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it bad practice to allow a UINavigationController to push view controllers that could lead to a repeating stack?

I'm building an app with a UINavigationController where I push a UIViewControllers, and IBActions on one of the classes can cause another instance of the first type to be pushed:

ViewControllerType1 --> ViewControllerType2 --> ViewControllerType3 --> ViewControllerType1

As you can see, its possible to have no 'end' to the stack.

Is this bad practice to have a never ending cycle like this? Should a UINavigationController stack be used with an 'end' in mind?

like image 271
barfoon Avatar asked Nov 05 '22 07:11

barfoon


1 Answers

It's fine to allow a "cycle" if that's what the user expects.

If you expect (and want to allow) the user to create deep stacks, you should try to minimize the amount of private state in each view controller. For example, if two view controllers on the stack both show the same information to the user, you should make both view controllers share the same underlying object holding that information.

You should also make sure each view controller releases as much as it can if it receives the didReceiveMemoryWarning message (if that view controller is not on top of the stack).

like image 142
rob mayoff Avatar answered Nov 09 '22 13:11

rob mayoff