[How-To] Save when a View is showing upon Quit [Please]

Discussion in 'iOS Development' started by cocotutch, Jul 11, 2009.

  1. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    Hi there everybody,

    I need some help this time, now first cab off the rank -- I have used the Docs to find the methods I want to have this happen in, I have Googled to no avail, and I have looked at Apple Sample Code, but it confuses me.

    Ok, next up is the code I want to use:

    [OBJC]- (void)applicationWillTerminate

    Please Register or Log in to view images

    UIApplication *)application {
    if(![[NSUserDefaults standardUserDefaults] boolForKey

    Please Register or Log in to view images

    "IsPlayingField"]) {

    [[NSUserDefaults standardUserDefaults] setBool:YES forKey

    Please Register or Log in to view images

    "IsPlayingField"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    }
    }[/OBJC]

    What I want to do, is save when the user is on the playing field which is "BallView". If they quit while bouncing my Stress Ball (yes, I made Stress Tool --App Store-- if you have heard of it -- This is for an Update) I want the game to save in the state in which it quits, I just dont know how to go about adding this functionality.

    Please help me,

    cocotutch
  2. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Assign tags to your views. That way, you can easily write out the tags to the user defaults and read them back, doing whatever you need to when the application reopens.
  3. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    **Freaks out** I don't know how to do anything is NSUserDefaults, the only stuff I know is very very very very very very basic NSDictionary for BOOLs, I have never done any thing like this before

    Please Register or Log in to view images

    I'm stuck, I broke Stress Tool twice with trying to do this

    Please Register or Log in to view images

  4. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    And that my friend is why we have SCM and the snapshot feature in Xcode.
  5. hitman2992

    hitman2992 New Member

    Joined:
    Dec 10, 2007
    Messages:
    123
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
  6. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    Hmmn, thing is I dont need to save Data as such, I just want to save the current state of the application (if the Playing Field is showing on Quit). The user can just reset their two preferences since saving them is impossible for me.

    cocotutch

    EDIT: I will have a look at that tutorial, and experiment in a sample project until I get it working, but now off to read a boring book for school

    Please Register or Log in to view images



    EDIT 2: I have success with saving Ball.radius' Size, but not when the View is showing nor colour.

    Please Register or Log in to view images

  7. Cyanidepoison

    Cyanidepoison Active Member

    Joined:
    Jan 18, 2008
    Messages:
    1,076
    Likes Received:
    2
    I don't use those because I'm a bad person.

    Please Register or Log in to view images

  8. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    And I thought I was bad for never, ever, using them. I didn't even know what SCM and Snapshots were used for. Even now I know what they are, I won't use them

    Please Register or Log in to view images

    On top of everything else I have to remember.........
    ------------------double post merged------------------
    Okay, the slider value is NOT saving for some random reason, god why didn't Apple just make NSUserDefaults as easy as
    Code:
    [slider.value.saveValue = YES]; 
    and have it load with
    Code:
    [slider.value = saveValue];
    ? its just NOT working. Could somebody please give me a light snippet of code that would at least save and reload my slider value for me? I could then learn from that and try to save my [OBJC]Ball.color = [UIColor colorNameHere].CGColor;[/OBJC] into it too, I have multiple swatches that the user can choose from, but it gets annoying choosing the colour every time.


    EDIT: If somebody could also add to the code snippet how to save "what view is currently showing and have it reshow on App relaunch", it would be fantastic, a free copy of my App Store App "Stress Tool pro" which is coming out soon (its in Review) would be headed your way as I am giving out 16 or 17 promo codes upon its or the updates release. Better yet, can you (the mystery someone) do this for me?

    cocotutch
  9. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    *Gets the stake and matches ready* Anyway try it out, can save you from a lot of unexpected mishaps.

Share This Page