cocoa touch - How do you change button text dynamically when button is subview of a custom cell in iOS? -


i making ios app , has table view prototype cells. configure cells in cellforrowatindexpath method , works fine, come trouble when want change text in button after created. want changes button text when tap button. tried do:

[button settitle:@"change" forstate:uicontrolstatenormal]; 

inside of clickmethod runs when click the button, changes text in last cell no matter button press. tried above doesn't work because have multiple instances of same button.(one in every row) know how can change text of button click on only. code creates button:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath: (nsindexpath *)indexpath { cell = [tableview dequeuereusablecellwithidentifier:@"cell" forindexpath:indexpath]; //configure cell button = [uibutton buttonwithtype:uibuttontyperoundedrect]; [button addtarget:self action:@selector(clickmethod:) forcontrolevents:uicontroleventtouchupinside];   [button settitle:@"button" forstate:uicontrolstatenormal] [button settag:6789];//set tag can identify button button.frame=cgrectmake(218, 5, 99, 53); [cell addsubview:button];//put button in cell [cell setindentationwidth:45]; [cell setindentationlevel:1]; return cell;//return cell object 

help appreciated. can post more code, don't believe relevant question. in advance.

you can't set title on button cellforrowatindexpath: method calls multiple times. if button globally declared change title last button. that

-(void)clickmethod:(id)sender {     [sender settitle:@"change" forstate:uicontrolstatenormal]; } 

sender have instance of clicked button.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -