Question abut multiple views

Discussion in 'iOS Programming' started by Wikiboo, Jun 25, 2011.

  1. Wikiboo macrumors newbie

    Joined:
    Jan 1, 2011
    #1
    Is it possible to create a viewcontroller that could handle 5 views?
    And is it possible to implement a different button on every view to make a transition to root view?
    Code:
                                   ----- View1
                                   I
                                   ----- View2
                                   I
    ViewController --> MainView -------- View3
                                   I
                                   ----- View4
                                   I
                                   ----- View5
    
    So my idea of the app is when I load it it takes me to main window, and on that window there will be 5 button that will take me to the 5 views, and after I'm in that view, among other buttons there will be just one button that will take me only to the MainView.

    Let's say that some of those 5 views will be Options, Score, Statistics, something like that.

    If it is possible to make an app like that using so much views, is it a good approach?
     
  2. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #2
    What you describe seems to be the classic navigation calling mechanism for UIViewControllers. Typically you see a back button on the upper left of the navigation bar for those type of called views.

    You can also just do what you want with one top level view that swaps out one view for another. The 'back' button would have some call to remove the current view and replace it with your main view.

    You could also use a tab bar or a tool bar.

    If you don't know of these possibilities, then I think you have some more studying to do. This is common iOS developer knowledge.
     
  3. Wikiboo thread starter macrumors newbie

    Joined:
    Jan 1, 2011
    #3
    I'm working on app which keeps score to one game, first screen is like a paper block which will display a score, but to add a score I want to call another view in which a user can type the score, and after he pushes Insert it will sum the score and display it on first screen

    I have mainControllerView which loads ApplicationControllerView(first screen) on startup, and from that ApplicationControllerView I want to load 5 views (settings, statistics, insert score, and two more)

    What is the best way to do this?

    And one more thing, what is the difference between addSubview, pushViewController and presentModalViewController?

    I've read the Apple doucumentation but I'm confused, becaue I don't quite understand the difference, all 3 methods show another view on screen, I don't know when to use those methods?
    Do you have some example?
     
  4. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #4
    I'd say that is a personal design decision. With the little information you have provided, I'm favoring using a toolbar because it seems all the 'sub screens' are directly related to the 'top' screen. BUT, you describe entering a score and that kind of action would suggest using a view controller for that because that is the common convention.

    Read the iOS Human Interface Guidelines


    Yea, you really need to do some more reading. Perhaps get a decent book. Check Amazon for ratings.

    I couldn't find a clear explanation for modal in the Apple docs. I'm not saying it isn't there, just that I couldn't find it in a very short time. The jest of it is that you are presenting a view/window/action that requires feedback from a user before they are allowed to continue acting in the normal flow your app. When that task has been completed, the view/window disappears and the flow is returned to where it was interrupted. Here is Apple's docs on Modal View Controllers. Also consider what an alert view does.

    You may need to consider that view controllers on iOS are full screen for iPhone and iPod, but not necessarily for iPad on on OS X.

    If you don't understand addSubview:, you really need to backup. A view can contain zero or more subviews and those subviews can contain zero more subviews, and those, well it can just keep going on. A subview is usually smaller than it's parent's view but doesn't have to be. When you use addSubView:, you are adding a view on top of another view which will become the parent view of the view being added. That is the usual way you build a complicated presentation. When using Interface Builder, you do that by drag and dropping elements.
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    addSubview: does exactly that: it adds a view to an existing view. Generally this is not used when you want a view to completely replace an existing view on the screen.

    pushViewController: is used to push a new view controller into the navigation stack. This replaces the current view with the new view and provides the mechanism to go back through the stack. This only works if you are presenting your view controllers within the context of a UINavigationController

    presentModalViewController: is used to display a new view controller (generally replacing the existing view on screen) without any of the navigation stack. It is the equivalent of a modal dialog/alert on a desktop OS.

    In general for what is being described here you should have a UINavigationController and be pushing view controllers into the stack as this will provide the expected behaviour and ability to return from, say, Options back to the main view.
     
  6. Wikiboo thread starter macrumors newbie

    Joined:
    Jan 1, 2011
    #7
    Thanks guys, I understand it better now, I will go now one more time through Apple documentation to learn it better
     

Share This Page