problem with navigation bar

Discussion in 'iOS Programming' started by sgs1, Oct 11, 2014.

  1. sgs1 macrumors newbie

    Joined:
    Jul 14, 2014
    #1
    Hello!

    I've two view controller.

    In the first, i write my room's name (for example bedroom) and push the button.
    In second view, i see the name of my room, and insert other details, like number of bulbs, name of bulbs and when i've finished, I press on a button that keeps me coming back to first controller.

    I'm using uinavigation bar for this two steps, but i have a question.

    If I press on bedroom's button, i don't see the details that i've wrote before.
    How i can see that?
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    What you describe is often called a Master-Detail design. The master view shows a list of items, like rooms in a house, and tapping an item shows a detail view with the details of that room, like the number of bulbs that you mentioned.

    Xcode will build for you a Master-Detail Application if you choose File > New > Master-Detail Application. I recommend that you try that and look at the resulting app.

    In order for your app to remember any details that the user has entered the app needs to save them. These can be saved in-memory or better can be saved to a file. It could even save it to the cloud if you want.

    There are lots of choices on how to save the detail information. The most common would be using a sqlite database or using plist files. I recommend that as a beginner you use plist files. This is a strategy that's widely used so you should learn it.

    I can't explain the entire strategy here but I'll give a few details. Each plist file will represent the details for a room. Each plist file will contain a NSDictionary that contains key/value pairs that represent the details.

    Name the plist files the same as the room (bedroom.plist, kitchen.plist, etc.)

    Store the plist files inside the Application Support folder in your app sandbox.

    When the user taps a room in the Master view load the plist file
    Code:
    NSDictionary dictionaryWithContentsOfFile:
    . If the file doesn't exist simply create a new NSMutableDictionary. Then assign the plist file to the detail view in prepareForSegue.

    The detail view should read all of its data from the NSDictionary. When the user edits the data and closes the detail view write out the plist file
    Code:
    NSDictionary writeToFile:
    You'll need to use NSMutableDictionary for editing.

    See these links for more info on plist files:

    https://www.google.com/search?hl=en...mages&tbs=&as_filetype=&as_rights=&gws_rd=ssl
     
  3. sgs1 thread starter macrumors newbie

    Joined:
    Jul 14, 2014
    #3
    Thanks for the reply.

    Another question: i have to set more views and go forward and back without problem.
    Now: i'm using uinavigationbar for 1 or 2 views and i have problem with more views.
    Can this type of design resolve this problem?
     

Share This Page