我有一個表格視圖,它的單元格本身有一個按鈕,這些按鈕應該用唯一的ID打開一個視圖。所以我需要傳遞一個參數給我的按鈕,但是addTarget
屬性我可以調用沒有任何參數的函數。在表視圖單元格中添加按鈕的目標
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
...
cell.editButton.addTarget(self, action: #selector(goToEdit(id:)), for: .touchUpInside)
}
func goToEdit(id: String) {
let edit = EditAdViewController(editingAdId: id)
self.navigationController?.pushViewController(edit, animated: true)
}
有什麼辦法可以將一些參數的動作引用到按鈕上嗎?謝謝大家:)
https://stackoverflow.com/a/46379494/3746301 – Shades