ios - Need help figuring out how to save my BOOL inside my button -


i placed bool inside uibutton. if click on button once, want bool saved never has click on button again while in game. used following code doesn't work save. however, code should work. it's final line of code makes saving not work. doing wrong?

-(void)viewdidload{  [[nsuserdefaults standarduserdefaults] setbool:redguy forkey:@"save"];  if (redguy==[[nsuserdefaults standarduserdefaults]synchronize]) { man.image=[uiimage imagenamed:@"red.png"]; }  redguy=[[nsuserdefaults standarduserdefaults]boolforkey:@"save"]; } 

edit:

if (redguy==yes) {     [[nsuserdefaults standarduserdefaults] setbool:redguy forkey:@"save"];      redguy =[[nsuserdefaults standarduserdefaults]boolforkey:@"save"];      man.image=[uiimage imagenamed:@"red.png"]; } 

this assumption since didn't clarify else going on in code, looks bool redguy going be no on viewdidload, , if condition false since synchronize yes (not mention, comparison makes no sense , it's necessary call synchronize since synchronization user defaults happens on own).

a simple way determine if button has been pressed before add following button action method.

- (void)buttonaction:(id)sender {     [[nsuserdefaults standarduserdefaults] setbool:yes forkey:@"save"]; }  - (void)viewdidload {     bool hassaved = [[nsuserdefaults standarduserdefaults] boolforkey:@"save"];     if (hassaved) {         // can hide button here if that's you're going         [yourbutton sethidden:yes]     } } 

is trying accomplish? determining if specific button has been tapped before?


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -