How to save a checkbox value when click a save button in ios -
i have check box designed through button , able alter checkbox images unable save lastly image checked in checkbox when click on save button.
i have page in check box there , save button action there when click on save value in checkbox must saved , when 1 time again re-enter in screen previous whatever value in checkbox must seen, me every time when come in screen checkbox seen empty.
hope helps me out.
bool checked; - (ibaction)canfollowaction:(id)sender { uibutton *tappedbutton = (uibutton*)sender; if([tappedbutton.currentimage isequal:[uiimage imagenamed:@"checkbox.png"]]) { [sender setimage:[uiimage imagenamed:@"selected.png"] forstate:uicontrolstatenormal]; } else { [sender setimage:[uiimage imagenamed:@"checkbox.png"]forstate:uicontrolstatenormal]; } } - (ibaction)btnsaveaction:(id)sender { if(checked) { [btncheckcanfollow setimage:[uiimage imagenamed:@"selected.png"] forstate:uicontrolstatenormal]; } else { [btncheckcanfollow setimage:[uiimage imagenamed:@"checkbox.png"] forstate:uicontrolstatenormal]; } [self.navigationcontroller popviewcontrolleranimated:yes]; [[[itoast maketext:@"successfully updated"]setgravity:itoastgravitybottom]show]; }
you must save state in nsuserdefaults!
for illustration on button click
if (button.selected) { [button setselected:yes]; [[nsuserdefaults standarduserdefaults]setobject:[nsnumber numberwithbool:yes] forkey:@"remember_me"]; }
and check on viewdidload
if([[nsuserdefaults standarduserdefaults] boolforkey:@"remember_me"] == yes) { [button setselected:yes]; [button setimage:[uiimage imagenamed:@"selected.png"] forstate:uicontrolstateselected]; } else { [button setselected:no]; [button setimage:[uiimage imagenamed:@"checkbox.png"] forstate:uicontrolstatenormal]; }
ios
No comments:
Post a Comment