I feel bad asking three questions in the space of two days but I am stuck and searching the forum I couldn't find the answer so I hope someone can help me - all part of the fun of learning I suppose!
In my program I have three views which go in the order GridScreen -> GameScreen -> CorrectScreen. On the CorrectScreen I have a button which goes back to the GridScreen.
On the GridScreen I have a bunch of buttons which a user can press to go to the GameScreen. When the user answers the question correctly he is taken from the GameScreen to the CorrectScreen for acknowledgement and then back to the GridScreen.
In a previous question I asked how to track the button that was pressed on the GridScreen so that when I go back to it from the CorrectScreen I can replace the icon with a tick. That was solved earlier but by doing so I've created another problem.
In the CorrectScreen, when the user presses the button to go back the following two functions are called:
[self.gridScreen updateUserIcon:buttonThatWasPressed];
[self.gridScreen updatePoints:accumulatedpoints];
where updateUserIcon is:
-(void)updateUserIcon:(UIButton *)button
{
UIButton *buttonPressed = button;
self.button1 = buttonPressed;
[self.button1 setImage:[UIImage imageNamed:@"tick.png"] forState:UIControlStateNormal];
}
and updatePoints is:
-(void)updatePoints:(int)points
{
self.currentPoints.text = [[NSString alloc]initWithFormat:@"Current points: %d", points];
}
where button1 is a UIButton and currentPoints is a UILabel.
Now, when I go back to the GridScreen using the following code after calling the two functions the tick appears on the button I want, but the label does not update correctly: FIRST CASE:
[[[self presentingViewController]presentingViewController] dismissModalViewControllerAnimated:YES];
whereas if I use this next way, the tick does not appear at all, but the label updates perfectly: SECOND CASE:
GridScreen *screen = [[GridScreen alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:screen animated:YES];
(I normally load views using the second case).
In the first case, even if I did the following code:
-(void)updatePoints:(int)points
{
self.currentPoints.text = @"A";
NSLog(@"Current Points %@", self.currentPoints.text);
}
My NSLog returns Current Points (null).
The solution is something to do with my first method of going back to the GridScreen I don't actually load the view again but in the second method I do - but I cannot understand what I need to do to get both the score updating correctly and the tick.
If anyone can help I would love to know - I am fairly new to programming with Objective-C so if any of this is 'bad code' I am happy to be told what is wrong so going ahead I don't make similar mistakes.
Thanks again to you all, this site is fantastic for helping out and in advance I appreciate the advice.
Andy.