views:

44

answers:

1

I want my view controller to display different views based on a condition that depends on some runtime checks (lets say a uiwebview at even hours and a form on odd hours). What is the best pattern to achieve it in iphone project? Maybe I can hide controls based on aforementioned condition or maybe it is better to load different views? or maybe i should load different view controllers and make the check in my parent view controller?

A: 

The iPhone UI is so small and crowded that you are usually better off creating a different view/view-controller pair for different UIs. Hiding UI elements leaves gaps that are very noticeable and manually rearranging the UI elements on the fly is a pain.

More importantly, different views communicate to the user that the app is in a different state. You don't want the app to switch to a different state without informing the user. It's hard enough for them to understand what is going on without confusing them with UI slight of hand.

It is very bad UI design to have the same user action present a different UI for no reason discernible to the user. For example, presenting a "a uiwebview at even hours and a form on odd hours" would be a fantastically bad idea because the user would have no idea why clicking on a specific button sometimes gets them a web view and a form view other times. Do you expect the user to check the clock before clicking so that they know what to expect?

If some UI element is unavailable for some reason e.g. no network access, then it's better UI design to present the element as disabled instead of disappearing it. The interface grammar teaches users that grayed out controls are temporarily unavailable. That is much less confusing that a constantly changing UI.

TechZen
thats a sensible tip.If i decide to use a separate viewcontroller/view pair for each screen how do I manage the switching logic? do I have to use some kind of navigationcontroller to switch between the views? sorry i am a noob in cocoa touch world :/
adrin
A navigation controller is easiest to use and you don't have to actually show it. To swap out a different view just have a test for your state and then push the specific view for the present state onto the navigation controller's stack.
TechZen