ios - Updating UIButton State in TableViewCell Changes other Rows -


my table view contains uibutton inside each row , depending if user has redeemed change it's image , whether disabled or enabled.

when user purchases item (say item 0 first row @ times) want notify app should switch image , disable button @ specific row. i'm using nsuserdefaults alert tableview.

in other words if user clicks on item 0 asked if redeem or cancel, if user presses redeem, following:

[[nsuserdefaults standarduserdefaults] setbool:yes forkey:@"itemzeroredeemed"]; [storetableview reloaddata]; 

in cellforrowatindexpath do:

if([[nsuserdefaults standarduserdefaults] boolforkey:@"itemzeroredeemed"]) {     if(indexpath.row == 0) {         [cell.productinfobutton setbackgroundimage:[uiimage imagenamed:@"itemunlocked"] forstate:uicontrolstatenormal];         cell.productinfobutton.enabled = no;     } } 

it works in updates tableview , row correctly, when coming later. issue farther down list item 5 being updated new button state. how can fix since want specified button updated?

the problem due cell reusing mechanism. each cell should reset default status this:

if([[nsuserdefaults standarduserdefaults] boolforkey:@"itemzeroredeemed"] && indexpath.row == 0) {     [cell.productinfobutton setbackgroundimage:[uiimage imagenamed:@"itemunlocked"] forstate:uicontrolstatenormal];     cell.productinfobutton.enabled = no; } else {     [cell.productinfobutton setbackgroundimage:[uiimage imagenamed:@"__default_image__"] forstate:uicontrolstatenormal];     cell.productinfobutton.enabled = yes; } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -