return to the viewDidLoad

Discussion in 'iOS Programming' started by todizara, Feb 27, 2011.

  1. todizara macrumors newbie

    Joined:
    Dec 17, 2010
    #1
    I have a problem with my application. I did a quiz and when the game is complete, an alert is displayed asking if the user wants to continue or quit.

    If the user decides to leave, there is no problem, but if he decides to continue, I do not know how to return to - (void) viewDidLoad.

    I try [self viewDidLoad], the game is reloaded but the text is superimposed with the text of the previous games. I would find a way to erase the view and reload the game.
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    U could make a new void, post you're viewDidLoad code in there. and call that when they press continue x)
     
  3. todizara thread starter macrumors newbie

    Joined:
    Dec 17, 2010
    #3
    can you give more explanation !
     
  4. nickculbertson macrumors regular

    nickculbertson

    Joined:
    Nov 19, 2010
    Location:
    Nashville, TN
    #4
    Code:
    -(void)viewDidLoad{
    do stuff
    }
    
    -(void)newGame{
    same as viewDidLoad
    }
    Nick
     
  5. forum user macrumors regular

    Joined:
    Aug 28, 2008
    #5
    slight modification

    Code:
    
    -(void)viewDidLoad{
    do other stuff;
    [self newGame];
    }
    
    -(void)newGame{
    setup new game;
    }
    
    -alert {
    ask user: "Play again?"
    if yes then {[self newGame];
    }
    
    don't write code twice, refractor it and call the method twice

    - Olaf
     
  6. todizara thread starter macrumors newbie

    Joined:
    Dec 17, 2010
    #6
    you know, all my buttons are created dynamically, I create them in the viewDidLoad, and I do not know if it's possible to create a button dynamically in function
     
  7. forum user macrumors regular

    Joined:
    Aug 28, 2008
    #7
    One thing is to alloc a button, another one is to send text or stuff to a button. The alloc should happen once only, setting text can happen as often as you like.

    - Olaf
     
  8. todizara thread starter macrumors newbie

    Joined:
    Dec 17, 2010
    #8
    I tried what you said, but the problem still persists.
    If I do [self.view removeFromSuperview], how to reinsert the view.
     
  9. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #9
    The thing what u have to do is go like this

    in ur .H File, make a new void

    Code:
    - (void) gameLogic;
    in ur .M File u go like this

    Code:
    - (void) viewDidLoad {
    [self gameLogic];
    }
    Code:
    - (void) gameLogic {
    //Holy moly lot's of dynamiclylciicicly creating buttons in here n shizzle!
    }
    About the removeFromSuperview;
    depends when u want to call it, but what ur looking for is this

    Code:
    SomeViewController *nameOfSubview = [[SomeViewController alloc] initWithNibName:@"SomeViewController" bundle:nil];
    [self.view addSubview:nameofSubview];
    =)

    tadaa :p



    *EDIT* Don't forget, viewDidLoad only get's called once, unless u release it every time.
    Then u need to call the function of gameLogic, in ur
    Code:
    - (void) viewWillAppear:(BOOL)animated {
    [self gameLogic];
    }
     

Share This Page