【发布时间】:2015-04-22 15:01:35
【问题描述】:
我在开发 tableview 自定义单元格时经常遇到这个问题。
这是一个问题,我有一个 tableview,它有很多自定义单元格(一个 UIImageView 和 UILabel)当用户点击这个单元格中的任何一个会推送新的 UIViewController 并且用户填充一些数据并点击“保存”viewcontroller 用委托推回方法。
在此委托方法中,我检查点击的单元格并更改该色调颜色(如选定状态,但我只是更改自定义 imageview 色调颜色)。所以这会正确改变,但是当我滚动任何垂直方向时,色调颜色会消失。下面的图片和代码用于正确计算。
当从委托方法弹出视图控制器时(正常工作)
垂直方向滚动时可以
// 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 back
// 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
【问题讨论】:
标签: ios objective-c iphone uitableview custom-cell