Managing navigation in an iOS app

  • I'd like to get some opinions on handling navigation without having
    your view controllers modify the navigation stack directly.
    I'm currently working on an app where I've subclassed
    UINavigationController, which in turn has custom methods for showing
    the various views of the app. Each of my app's view controllers has no
    sense of the other pieces of the app, and do not push directly on the
    navigation controller. I'm thinking this a much better method since it
    decouples view controllers from each other and allows the flow of the
    app to be updated more easily.
    I'm using a lot of NSNotifications to signal commands to the
    navigation controller, and it's getting a bit messy. I love the idea
    of a centralized, decoupled navigation controller, but I haven't seen
    any good examples of this yet.
    I would love to get some feedback as to if this is a good idea in the
    first place, or techniques you've implemented to handle this sort of
    thing.

    Cheers,

    James
  • Hi James,

    I'd suggest that you're probably pushing the idea of decoupling things a bit too far here.

    View Controllers are inherantly tied to the behaviour of your application, and your user's experience of the flow through it.  In 95% of cases, it's absolutely correct for the view controller to know "the user pushed this button, therefore I should show them this other view controller".

    For the 5% of remaining cases where (for example) you have a highly reusable view controller that gets used in many different places in the app, and may push a different child VC depending on its usage location, I'd suggest simply using a delegate to that particular VC to allow you to separate out what gets pushed.

    Thanks

    Tom Davie

    On 21 May 2013, at 20:56, <jw...> wrote:

    > I'd like to get some opinions on handling navigation without having
    > your view controllers modify the navigation stack directly.
    > I'm currently working on an app where I've subclassed
    > UINavigationController, which in turn has custom methods for showing
    > the various views of the app. Each of my app's view controllers has no
    > sense of the other pieces of the app, and do not push directly on the
    > navigation controller. I'm thinking this a much better method since it
    > decouples view controllers from each other and allows the flow of the
    > app to be updated more easily.
    > I'm using a lot of NSNotifications to signal commands to the
    > navigation controller, and it's getting a bit messy. I love the idea
    > of a centralized, decoupled navigation controller, but I haven't seen
    > any good examples of this yet.
    > I would love to get some feedback as to if this is a good idea in the
    > first place, or techniques you've implemented to handle this sort of
    > thing.
    >
    > Cheers,
    >
    > James
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today