Saving a value for Current View Controller When App Terminates

Discussion in 'iOS Programming' started by sldice, Oct 29, 2010.

  1. sldice macrumors newbie

    Joined:
    Oct 24, 2010
    #1
    Hi,
    I've tried to ask a couple questions before as I am struggling figuring out how to return to current view when app terminates being new. I guess I was hoping someone could help me with this idea since i am new, and hopefully I can work it somehow.

    The question: I have multiple View Controllers as I am making a trivia game, so each xib file has its own question. So when the app terminates, can someone help me figure out how to save an integer depending on which View Controller is showing when app terminates?

    So when question4ViewController is in view I want to put something like :

    int save; // in the questionViewController.h file //
    save = 4; // in the questionViewController.m file //

    So when the app terminates, save has all ready been updated depending on which question is showing.

    So then if I can figure that part out, when the app launches, I have a main page where the user can click new game, or continue therefore returning to the question the user was on when the app terminated. The plan there would be to somehow do -(IBAction)Continue{

    if save = 3 it will go to question3ViewController
    if save = 4 it will go to question4ViewController
    and so on....

    I assume there is a much easier way like a NSARRAY to do this, since other wise I have to to the if save = 100 times if I have a 100 questions. Any help is much appreciated.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    I'd take a few steps back. Do you really need an xib for every question? Are they not all, basically, the same just with different text? In that case why are you not using a data file (plist, database, whatever) with the questions/answers and a single xib?
     
  3. sldice thread starter macrumors newbie

    Joined:
    Oct 24, 2010
    #3
    I'm sure you are exactly right. Being new and reading this stuff for months, it gets frustrating when all the pieces don't click yet. So that's probably why I have a xib for each question. Not understanding everything, creating the questions visually was very easy for me. Having 1 ViewController, and then code to create each question under one file, keeping score, and my 10'second timer is way above my head at this point. That's why I was hoping I could simply do the if save = blah blah, go to this view. I understand from your perspective, you are probably saying, "if you don't know how to do it the correct way programatically, stop trying to make an app, and learn how to do it first". If you have any ideas or a good tutorial to learn to make this database, and then save to return to current view that would be great. Thanks for your time.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    I don't use tutorials. I also don't think they help people learn: people end up copying them without understanding. The only way to really learn to program is to back up to the start and learn from the fundamentals starting with small, non GUI, command line programs and moving up in small steps. Trying to build an app without the basic knowledge is pointless.
     
  5. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #5
    I disagree. I've been programming a long time and everybody has a different learning style. Some people will look at a tutorial, and as you said, just copy and paste it 100 times and learn nothing. On the other hand, some people will look at a tutorial, and seeing how all the pieces fit together in a simple and step-by-step manner will be enough for it to "click" for them. I've always found the "basics" to be worthless for me. They rarely show you how all the pieces can stack together to make the proverbial "masterpiece".
     

Share This Page