2016-09-30 53 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

傻我:(。感谢这么多。 –