UIViewController as statemachine?
I want to have a general controller that acts as an abstract statemachine (not have any views/bars etc. of it开发者_JAVA技巧s own). Is the UINavigationController meant for this too?
I don't see any reason to use UIViewController
for this. UIViewController
inherently has a UIView
that it controls--you'd be ignoring most of what UIViewController
does. A custom controller object would probably be more appropriate, unless you need specific non-view functionality in UIViewController
(and I don't know why you would).
EDIT: Again, I'm not sure why UINavigationController
would be a better fit. UINavigationController
exists pretty much for the sole purpose of pushing and popping view controllers (along with displaying the navigation bar and whatnot). Unless there's some specific functionality you want that comes with UINavigationController
, I would just subclass NSObject
.
I'm not going to give you the best practise speach here. You can do it, and if it suits your needs and you can do it I say why not. If you feel its a bad idea you should look for other solutions. Or at least try it if you believe it can work.
Tbh I once wrote a C# application that had a Panel object as a statemachine by pointing it to other panels and maintain state specific code in my classes that inherited from the panel class.
精彩评论