我正在使用这个方法
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]?
{
let delete = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
//Do something
})
delete.backgroundColor = UIColor.redColor()
let more = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "More" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
//Do something
})
more.backgroundColor = UIColor.blueColor()
return [delete, more]
}我还包括了
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
// you need to implement this method too or you can't swipe to display the actions
}
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// the cells you would like the actions to appear needs to be editable
return true
}当我向右或向左滑动时,我创建的按钮不会出现。我尝试在editactionforrowatindexpath上设置覆盖,但随后得到一个错误,说明方法没有覆盖其超类中的任何方法
发布于 2016-07-02 16:41:55
在您的实现中没有任何错误。未调用该函数是因为委托和数据源方法未正确调用。
您可以通过编程或通过故事板连接委托和数据源方法。
当你以编程方式实现tableview时,你需要在类声明中添加UITableViewDataSource,UITableViewDelegate,并使用下面的代码连接委托。
yourTableView.datasource = self
yourTableView.delegate = self如果你是通过storyboard实现tableview,你只需要通过拖动来连接委托和数据源方法

https://stackoverflow.com/questions/38157219
复制相似问题