簡體   English   中英

iOS swift 3 編碼 tableview 編輯按鈕使用 UIButton 而不是 UIBarButton

[英]iOS swift 3 coding tableview edit button using UIButton instead of UIBarButton

我寫了以下代碼。 我試圖使它的功能類似於UIBarButtonItem編輯項功能,但使用UIButton代替,因為我有一個自定義導航欄,但我有幾個編譯錯誤。 該功能應該允許在按下按鈕時進行編輯,並在再次按下時完成編輯。

@IBAction func edit(sender: UIButton){
    if [tableView.isEditing] == YES {
        [self.tableView .setEditing(false, animated: false)]
    }
    else{
        [self.tableView .setEditing(true, animated: true)]
    }
}

你正在混合 Swift 和 Objective-C 代碼,應該看起來像這樣

@IBAction func edit(sender: UIButton) {
    if tableView.isEditing {
        tableView.setEditing(false, animated: false)
    } else{
        tableView.setEditing(true, animated: true)
    }
}

暫無
暫無

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

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