1

我需要获取当前选择的 UITableViewCell 作为它的点击。因此,当我的手指触摸屏幕/单元格时,我想运行一个方法,我可以从中说一些简单的话:

selectedCell = cell;

cell作为我刚刚点击的那个并且selectedCell是我存储的副本。

我正在使用自定义子类 UITableViewCell 这就是为什么我认为我遇到了麻烦。

4

2 回答 2

13

只需像这样在您自己的自定义 tableview 单元格上实现 setHighlighted:animated: 方法。

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];

    NSLog (@"setHighlighted:%@ animated:%@", (highlighted?@"YES":@"NO"), (animated?@"YES":@"NO"));
}
于 2013-02-15T16:10:57.493 回答
1

TouchDown
- setSelected:animated: 在这里触地时调用单元格本身,您可以通知单元格委托

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
   [self.delegate willSelectCell:self];
}

将自定义单元格委托声明为单元格的属性

@property id<MyCellDelegate> delegate;

TouchUP
将单元格保存在委托中

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
_selectedCell = [aTableView cellForRowAtIndexPath:indexPath];
}

只需注意 Cell Views 可以重用的事实

于 2012-12-06T17:07:27.693 回答