【发布时间】:2016-03-31 05:12:11
【问题描述】:
我有一个 UITableViewController。它有一个原型单元,并根据用户查询生成 0 到 100 个单元。加载后,如果用户点击单元格内的任何位置,除了特定按钮之外,我希望触发 IBAction。我有多个标签,如果用户点击它们,我仍然希望触发 IBAction。我该如何做到这一点?
这是我加载表格的代码:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! TypeOfActivityTableViewCell
cell.activityLabel?.text = activityNames[indexPath.row]
cell.bgImage?.image = UIImage(named: activityPic[indexPath.row])
cell.sloganLabel?.text = slogan[indexPath.row]
return cell
}
我不想在 tableView 中为 MVC 原则编写所有这些代码。
【问题讨论】:
-
您可以为此目的使用标签值
-
"EXCEPT for a specific button" - 所以你在单元格中有一个
UIButton和一些UILabels,并且想要在用户点击单元格中的任何位置时触发特定操作,除了按钮上。我说的对吗?? -
完全正确。这些单元格具有“漂亮”的背景,并带有标识它们是什么的文本。我希望用户能够点击它们,然后调用 IBAction,但单元格内还有一个特定的按钮应该执行其他操作。而且我还需要知道点击了哪个单元格索引,因为我有一个数组,其中包含需要达到的每个特定索引的特定值。比如用户点击第三个单元格,索引2,我需要有IBAction触发,然后加载mySpecialArray[indexPath.row]
标签: ios xcode swift uitableview