我不知道發生了什麼,我設置了button.tag
與錶行,當它到達行> 1,它會拋出LLDB。如果button.tag <= 1
泰伯維button.tag擲LLDB
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cells")! as UITableViewCell
let alertBtn = cell.viewWithTag(1) as! UIButton;
alertBtn.tag = indexPath.row
alertBtn.addTarget(self, action: Selector(("showAlert:")), for: UIControlEvents.touchUpInside)
return cell
}
它在哪裏拋出error.can你告訴我們,showAlert的implemetation。 – luckyShubhra
錯誤來自於當我設置按鈕標記時,即使我刪除了添加目標,它仍然會拋出相同的錯誤。它與添加目標無關 –
你想讓alertBtn = cell.viewWithTag(1)as做什麼? UIButton的;線。這裏你說的是帶有標籤1的視圖就是你的按鈕,然後你又想改變標籤,所以在重用狀態下你的標籤會有所不同,並且可能的原因是這條線。爲什麼你想從標籤中查看按鈕? –