I was hoping you could help answer an Objective-C based question for me that is currently stopping me continuing in my program.
I have a game where you have a grid of buttons title 1, 2, 3, etc. Each of those buttons takes you to a GameScreen UIView passing with it various pieces of information – i.e. name, age, etc. If the user answers the question correctly, he is taken back to the grid – where I now want the button that he pressed to display a tick rather than just a blank button with some text as before.
My problem is keeping track of the button that was pressed. When I go back to the main screen, I can’t figure out how to say ‘Change the button that I just pressed to a tick image’. All things so far have come out as (null).
When I press a button at first I use the ‘if([sender.currentTitle isEqualToString:@”1″]) to tags what information I want to pass through – which is fine but after that point when I have been through another view I lose which button has been pressed.
I could pass through a variable all the way through that’s unique to each button and come up with an if then else statement to test the value of the variable (i.e. if [questionansweredcorrectly isEqualToString :@”Question1″]) but as I may have a hundred or more buttons here that’s too troublesome.
I hope I have explained the situation well enough and that someone will be able to point out the method I need to use here.
Thanks in advance!
EDIT:
In response to how I load into other views I use the following style of coding:
GameScreen *screen = [[GameScreen alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:screen animated:YES];
and this is how I go to a new view – doing the same from another screen to go back to the main screen with the buttons. I don’t use storyboards in this piece. Does this help clarify how I go through the views? I do not use storyboards.
From what I understood you dismiss your first view completely. Or you reload the first view where as you should just show it again.
Not 100% on how your loading your views but I think this might help:
To show the previous view (with all the buttons) simply use this code in the view that you loaded on top of the first view:
Hope it helps!