3 回答

TA貢獻(xiàn)1869條經(jīng)驗(yàn) 獲得超4個(gè)贊
contentView
guard let cell = sender.superview?.superview as? YourCellClassHere else { return // or fatalError() or whatever}let indexPath = itemTable.indexPath(for: cell)
UITableViewCell
class MyCell: UITableViewCell { var button: UIButton! var buttonAction: ((Any) -> Void)? @objc func buttonPressed(sender: Any) { self.buttonAction?(sender) }}
cellForRowAtIndexPath
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! MyCell cell.buttonAction = { sender in // Do whatever you want from your button here. } // OR cell.buttonAction = buttonPressed(closure: buttonAction, indexPath: indexPath) // <- Method on the view controller to handle button presses.}
indexPath
- 3 回答
- 0 關(guān)注
- 1467 瀏覽
添加回答
舉報(bào)