2016-09-30 74 views
1

我寫了下面的代碼。我試圖讓它的功能像UIBarButtonItem編輯項目功能,但使用UIButton而不是因爲我有一個自定義導航欄,但我有幾個編譯錯誤。該功能應該允許在按下按鈕時進行編輯,並在再次按下時完成編輯。iOS swift 3使用UIButton代替UIBarButton編碼tableview編輯按鈕

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

回答

1

你混淆了斯威夫特和Objective-C代碼,應該是這個樣子

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

傻我:(。感謝這麼多。 –