Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

todizara

macrumors newbie
Original poster
Dec 17, 2010
29
0
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.
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
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.

U could make a new void, post you're viewDidLoad code in there. and call that when they press continue x)
 

forum user

macrumors regular
Aug 28, 2008
204
2
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
 

todizara

macrumors newbie
Original poster
Dec 17, 2010
29
0
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
 

forum user

macrumors regular
Aug 28, 2008
204
2
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

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
 

todizara

macrumors newbie
Original poster
Dec 17, 2010
29
0
I tried what you said, but the problem still persists.
If I do [self.view removeFromSuperview], how to reinsert the view.
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
I tried what you said, but the problem still persists.
If I do [self.view removeFromSuperview], how to reinsert the view.

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];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.