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
Post a Comment