ios - UITableview cell retain custom image view filter -


i faces issue when developing tableview custom cell.

here problem, have tableview , has lots of customized cell (a uiimageview , uilabel) when user tap of cell pushes new uiviewcontroller , user filling data , tapped "save" viewcontroller push delegation method.

in delegate method inspect tapped cell , change tint color (like selected state i'm changing custom imageview tint color). changes correctly when i'm scrolling vertical direction tint color disappear. below pictures , code figuring out correctly.

when pop view controller delegate method (works correctly)

enter image description here

when scrolling vertical direction tin

enter image description here

// custom cell  @interface customcell : uitableviewcell @property(strong, nonatomic) uiimageview *imageview; @property(strong, nonatomic) uilabel *titlelabel; @end  // custom cell implementation nothing special here.  // uiviewcontroller delegate method when pop // i'm filling specific color   @interface uiviewcontroller @property (strong,nonatomic) customcell *mycustomcell; @end  @implementation uiviewcontroller    - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     ...      _mycustomcell = (customcell *)[self.tableview dequeuereusablecellwithidentifier:@"customcell" forindexpath:indexpath];      ... }  - (void)usertappedbackbutton {     _mycustomcell.imageview.image = [cell.customimageview.image imagewithrenderingmode:uiimagerenderingmodealwaystemplate];     _mycustomcell.imageview.tintcolor = [uicolor colorwithred:0.27 green:0.58 blue:0.98 alpha:1]; } @end 

the problem have saving reference uitableviewcell cells being reused.

you need save information cell highlighted in manner, cannot influenced cells being reused. suggest using indexpath.

something following should work:

@property (nonatomic, strong) nsindexpath *lastselectedindexpath;   - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     ...      customcell *cell = (customcell *)[self.tableview dequeuereusablecellwithidentifier:@"customcell" forindexpath:indexpath];     if([indexpath isequal:self.lastselectedindexpath]) {         cell.imageview.image = [cell.customimageview.image imagewithrenderingmode:uiimagerenderingmodealwaystemplate];         cell.imageview.tintcolor = [uicolor colorwithred:0.27 green:0.58 blue:0.98 alpha:1];     }     ... }  -(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     // save selected indexpath     self.selectedindexpath =  indexpath; } - (void)usertappedbackbutton {     // reload row needs updated new tint color     [tableview reloadrowsatindexpaths:@[self.selectedindexpath] withrowanimation:uitableviewrowanimationautomatic]; } 

let me know if worked out.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -