uitableview - 通过 UIImageView 选择表格单元格
问题描述
我有一个视图,其中包含用户收到的一组消息,我正在尝试完成类似于 gmail 工作方式的用户体验。
我希望当用户点击用户的图像时,它会选择他们想要执行的任何操作(删除、标记为已读等)的行,然后如果他们点击其他任何地方,它就会显示消息。下面是一个基本的概念证明。
我考虑过在图像视图上设置一个轻击手势,但我觉得有比这样做更干净的方法,并且可能是表格视图中内置的东西,但我正在罢工。
解决方案
您要做的是根据位置具有单独的点击功能。您必须在单元格的每个部分添加单独的点击操作。
因此,在 TableView 的源代码中,您必须更新覆盖UITableViewCell GetCell
,以便它更新图像按钮并添加允许用户交互和添加单击手势的功能。
public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var cell = tableView.DequeueReusableCell (cellIdentifier);
// where cellIdentifier is you TableView Cell key
if (cell == null)
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
cell.TextLabel.Text = tableItems [indexPath.Row];
// Add other generic code above, but here's what you need
cell.ImageButton.UserInteractionEnabled = true;
var singleTapGestureRecognizer = new UITapGestureRecognizer(() => // Do work
);
cell.ImageButton.AddGestureRecognizer(singleTapGestureRecognizer);
return cell;
}
推荐阅读
- r - Docker compose - R 服务器 - 致命错误:您必须指定“--save”、“--no-save”或“--vanilla”
- javascript - 添加到数组后更改对象的值
- python - 将 pandas.DataFrame 列分配给具有默认值的系列
- c++ - C++中的多维变长数组
- http - 错误:该 URL 未使用可识别的协议
- json - 在 Swift 4 中使用可编码解析嵌套的 JSON
- python - 在 $PATH 中找不到可接受的 C 编译器 - 安装 Python 和 GCC
- php - 函数 create_function 在 PHP 7.2 中已弃用
- c# - 向应用程序各处的用户一次加载数据的推荐方法是什么?
- python - 在python中制作计算器,这种方法明智吗?