objective-c UITableView/UITableViewCell 点击事件响应?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1889200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 22:36:57  来源:igfitidea点击:

UITableView/UITableViewCell tap event response?

iphoneobjective-cuitableview

提问by Arman

I've been googling around to try to figure out what sort of event handles are called when one row (or cell) in a UITableView is tapped, but haven't been able to figure it out. I'm trying to change the image property of the cell when it's tapped.

我一直在谷歌上搜索,试图找出当 UITableView 中的一行(或单元格)被点击时调用什么类型的事件句柄,但一直无法弄清楚。我试图在点击时更改单元格的图像属性。

Thanks.

谢谢。

回答by MystikSpiral

There are two possible events when a table row is tapped: selecting the row and the accessory view (usually the "more details" type action).

当点击表格行时,有两种可能的事件:选择行和附件视图(通常是“更多详细信息”类型的操作)。

As long as you have registered a delegate for the UITableView, the following can be implemented and will be called on a touch:

只要您为 UITableView 注册了一个委托,就可以实现以下内容并在触摸时调用:

// Tap on table Row
- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath { ... }

// Tap on row accessory
- (void) tableView: (UITableView *) tableView accessoryButtonTappedForRowWithIndexPath: (NSIndexPath *) indexPath{ ... }