无法显示删除按钮

问题描述:

我试图实现一个闹钟应用程序就像苹果的时钟应用程序。点击左侧的编辑按钮,我想使表进入编辑模式,红圈在每个单元格的左侧(自定义UITableViewCell)并点击该红色圆圈想要在右侧显示“删除”按钮/动作。无法显示删除按钮

我一直在尝试很多,经历了很多网站,但仍然无法弄清楚。有人可以看看我正在犯什么错误吗?

我已经提到下面和许多其他链接: How to enable swipe to delete cell in a TableView? UITableViewCell, show delete button on swipe

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) 

} 

} 

你应该实现 tableView(_:editingStyleForRowAtIndexPath:)并返回.Delete

+0

我实现了,但它并没有任何区别。 self.navigationItem.leftBarButtonItem = self.editButtonItem()//点击编辑按钮完成按钮,但表格不进入编辑模式。但是,当我在编辑按钮上设置** @ IBAction **时,出现红色圆圈按钮,但在滑动时不显示任何事件。每当我尝试滑动单元格时,我也会收到此消息:** MyApp [944:17497]必须有滑动才能删除确认视图,以便在安装滑动删除gobbler时** – user5407225