簡體   English   中英

如何在UITableViewCell中禁用UIButton

[英]How to disable a UIbutton in a UItableviewcell

您好,我目前有一個UItableview,在該表視圖中,我制作了一個包含兩個UIButton的自定義單元格。 這是為了實現上下投票功能。 我只是想知道在用戶單擊它后如何禁用單元格中的這些uibutton,而不會影響使用同一模板的其他單元格按鈕?

我試過在uitableviewcell的控制器中運行一個函數。 當單擊按鈕時,我會禁用按鈕,但是使用這種方法使我遇到了一個錯誤,其中其他單元格按鈕也將被禁用。

@IBOutlet weak var down: UIButton!
@IBOutlet weak var up: UIButton!


@IBAction func upVoteButton(_ sender: UIButton)
{

    self.up.isEnabled = false

}
@IBAction func downVoteButton(_ sender: UIButton) {

    self.up.isEnabled = false
}

請幫忙! 提前致謝。

據我認為,我更喜歡創建一個checkList:[Bool]數組,並在視圖中加載方法或嘗試設置表的任何方法,然后將表的長度數組配置為true,何時@IBAction被調用然后執行此操作

let cell = sender.superview?.superview as! UITableViewCell
    let tableview = cell.superview?.superview as! UITableView;
    let index = tableview.indexPath(for: cell);
    let n = index?.section/row // whatever u r using
     checkList[n] = false;

現在在重寫func tableView(_ tableView:UITableView,cellForRowAt indexPath:IndexPath)-> UITableViewCell執行此操作

cell.button.isEnabled = checkList[indexPath.section/row]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM