在自定义 UITableViewCell 中使用 UIButton 模拟 didSelectRowAtIndexPath

Posted

技术标签:

【中文标题】在自定义 UITableViewCell 中使用 UIButton 模拟 didSelectRowAtIndexPath【英文标题】:Simulate didSelectRowAtIndexPath with a UIButton in a customized UITableViewCell 【发布时间】:2011-10-12 07:22:16 【问题描述】:

我在自定义 UITableViewCell 中有一个 UIButton,它是 UITableViewCell 的子类。

UIButton 在 IB 中是 IBOutlet-ed,而 IBAction-ed 是一个函数:

- (IBAction)clickRead:(id)sender;

现在,当我单击按钮时,按钮没有响应,因为函数内部没有任何内容。我应该在函数中写什么,以便 UIButton 可以模拟 tableView 的didSelectRowAtIndexPath 函数(即选择表格单元格)?

【问题讨论】:

您的意思是当您单击任何一行的按钮时应该选择该行? 是的!如果单击该行上的按钮,则应选择该行并调用函数 didSelectAtIndexPath。 【参考方案1】:

这个答案可能会有所帮助:hitting a next button for a UITableViewcell

您可以调用 UITableView selectRowAtIndexPath:animated:scrollPosition: 以直观地选择行,但您仍然需要自己管理任何事件:加载另一个视图、调用 didSelectRowAtIndexPath:、故事板转场等。

【讨论】:

以上是关于在自定义 UITableViewCell 中使用 UIButton 模拟 didSelectRowAtIndexPath的主要内容,如果未能解决你的问题,请参考以下文章

UIbutton 在自定义 UITableViewCell 中释放

在自定义 UITableViewCell 中更改 UILabel 的颜色

UILabel 在自定义 UItableviewcell 中显示(空)

如何借助 AutoLayout 在自定义 UITableviewCell 中添加自定义 UIView(xib)?

我是不是需要在自定义 UIView 中使用单独的 UILabel 才能在 UITableViewCell 中有单独的 UILabel 行?

在自定义UITableViewCell中保持UIImageView的宽高比