ios - Show the progressBar that correspond to row of TableView when click with Custom TableViewCell -
i stuck few hours problem. have 3 rows in tableview. use custom cell contained 1 button , 1 progressbar. problem when click on button @ first or second row, progressbar show @ third row. don't know why. want show progressbar correspond row clicked.
@interface viewcontroller_ () { customviewcell *cell; } @end - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; cell = (customviewcell*)[tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell==nil) { nsarray *nib; nib = [[nsbundle mainbundle] loadnibnamed:@"issueviewcell" owner:self options:nil]; (id oneobject in nib) if ([oneobject iskindofclass:[customviewcell class]]) cell = (customviewcell *)oneobject; } cell.progressbar.hidden = yes; [cell.downloadbutton settitle:@"download" forstate:uicontrolstatenormal]; [cell.downloadbutton addtarget:self action:@selector(downloadbuttoncliked:) forcontrolevents:uicontroleventtouchupinside]; } -(void) downloadbuttoncliked:(uibutton *)sender{ nslog(@"called when press"); cell.progressbar.hidden = no; }
you not getting cell in right way. cell instance last cell loaded table view.
you should remove cell reference, don't need it.
you can change code this:
-(void) downloadbuttoncliked:(uibutton *)sender{ nslog(@"called when press"); customviewcell *buttoncell = (customviewcell*) sender.superview.superview; //if add button cell view should call sender.superview; buttoncell.progressbar.hidden = no; }
Comments
Post a Comment