【发布时间】:2015-09-17 14:27:18
【问题描述】:
问题
我需要在自定义 UITableViewCell 中的 touchDown 事件上更改 contentView 的 backgroundColor 属性。我在单元格中添加了一个 UIButton,但似乎无法弄清楚如何让它重新加载单元格并更改单元格的 contentView backgroundColor。
我的尝试:
我将目标添加到 cellForRow:atIndexPath: 中的 UIButton 中,如下所示:
[cell.touchButton addTarget:self action:@selector(touchButtonAtIndexPath:) forControlEvents:UIControlEventTouchDown];
这是我应该重新加载所选单元格的方法:
-(void) touchButtonAtIndexPath:(NSIndexPath *)indexPath {
cellSelected = YES;
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
}
当该单元格重新加载时,这是应该更改 contentView 的背景颜色的代码:
if (cellSelected) {
cell.contentView.backgroundColor = [UIColor blueColor];
}
我在 touchButtonAtIndexPath: 方法中收到错误,这是错误:
-[UIButton section]: unrecognized selector sent to instance
有谁知道如何在 touchDown 上更新自定义 UITableViewCell 的 contentView backgroundColor?谢谢!
【问题讨论】:
标签: ios objective-c uitableview uibutton