text field retain status even after closing the app

Discussion in 'iOS Programming' started by shahab47, Apr 15, 2012.

  1. shahab47 macrumors newbie

    Joined:
    Apr 8, 2012
    #1
    Hello there.

    I have 2 textfields in my very simple app.
    When I run it in simulator and enter text in these two fields and then close the app (simulator is still running). And then open the app , I see that the text I entered earlier is still present.

    How do I make sure that whenever my app is opened, the text field should be empty and it should not remember the contents present, the last time the app was opened.

    Thanks
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    Look up UIApplicationDidBecomeActiveNotification, UIApplicationWillResignActiveNotification, and similar notifications. Your view controller should register for one or more of these notifications and return itself to whatever state you need when the app opens due to its icon being tapped.
     
  3. shahab47 thread starter macrumors newbie

    Joined:
    Apr 8, 2012
    #3
    it would be great if you can explain this with the help of an example..The documentation is overwhelming.
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    Does the viewWillAppear get triggered on that viewController when you come back from the background?
    And what Phoney means in your appDelegate function (get back from background) -> UINotificationCenter, you can POST a NOTIFICATION, and in your viewController you can OBSERVE a NOTIFICATION.
    That should give you enough keywords to move on.
     
  5. shahab47 thread starter macrumors newbie

    Joined:
    Apr 8, 2012
    #5
    Thanks a log jnoxx. However I am a beginner. Never worked with C or GUI.
    Could you please explain with the help of an example ?
    or just a line of code which explains your steps?

    Thanks
     
  6. PhoneyDeveloper, Apr 17, 2012
    Last edited: Apr 18, 2012

    PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    Let me suggest that this is not the way to learn iOS development. Follow an online course like the Stanford lessons or get a book and read it cover to cover. If you ask a question but don't understand the answer then you need to start with the basics.

    jnoxx, I really meant what I said. Register for one or both of those notifications. The app delegate has nothing to do with it.
     
  7. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #7
    I know what you said, and you are 100% Correct, i thought i'd lay it out for him, but i understand what you did, might be a better way for single VC's to handle it off.
     

Share This Page