Swift2 无法显示删除按钮

Swift2 无法显示删除按钮,swift2,ios9,xcode7,Swift2,Ios9,Xcode7,我正在尝试实现一个闹钟应用程序,就像苹果的时钟应用程序。点击左侧的编辑按钮,我想让表格进入编辑模式,每个单元格(自定义UITableViewCell)的左侧都有红色圆圈,点击红色圆圈,我想显示“删除”按钮/操作位于右侧。 我已经尝试了很多,浏览了很多网站,但仍然无法找到答案。有人能看看我犯了什么错误吗 我参考了以下和许多其他链接: 您应该实现 tableView(uu:editingstyleforrowtaindexpath:)并返回。我实现了Delete,但没有任何区别。self.navi

我正在尝试实现一个闹钟应用程序,就像苹果的时钟应用程序。点击左侧的编辑按钮,我想让表格进入编辑模式,每个单元格(自定义UITableViewCell)的左侧都有红色圆圈,点击红色圆圈,我想显示“删除”按钮/操作位于右侧。

我已经尝试了很多,浏览了很多网站,但仍然无法找到答案。有人能看看我犯了什么错误吗

我参考了以下和许多其他链接:


您应该实现


tableView(uu:editingstyleforrowtaindexpath:)
并返回
。我实现了Delete

,但没有任何区别。self.navigationItem.leftBarButtonItem=self.editButtonItem()//点击编辑按钮时,会出现“完成”按钮,但表格不会进入编辑模式。但当我在编辑按钮上设置@iAction时,红色圆圈按钮出现,但在滑动时没有事件。每当我尝试滑动单元格时,我也会收到此消息:安装滑动删除gobbler时,MyApp[944:17497]必须具有滑动删除确认视图
class SavedAlarmListViewController: UIViewController,UITableViewDataSource,UITableViewDelegate{

@IBOutlet weak var tableView: UITableView!

var alarms = [AlarmDataObject]()

override func viewDidLoad() {
super.viewDidLoad() 
self.tableView.delegate = self
self.tableView.dataSource = self
self.navigationItem.leftBarButtonItem = self.editButtonItem()

}

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
refreshList()
}

func refreshList() {

alarms = AlarmsList.sharedInstance.allSavedAlarms()
tableView.reloadData()

}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return alarms.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cellIdentifier = "cell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! AlarmTableViewCell

// custom code to set data ....

return cell
}


func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true // all cells are editable
}

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
let alarm = alarms.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
AlarmsList.sharedInstance.removeAnAlarm(alarm) 
}
}

}

class AlarmTableViewCell:UITableViewCell {
// IBOutlets

override func awakeFromNib() {
super.awakeFromNib()

}

override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

}

}