Ios TableView操作没有';不显示
我使用以下代码创建了UITableViewRowAction:Ios TableView操作没有';不显示,ios,swift,uitableview,Ios,Swift,Uitableview,我使用以下代码创建了UITableViewRowAction: func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { var deleteAction = UITableViewRowAction(style: UITableViewRowActionS
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete", handler: {(action:UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
})
if editingStyle == UITableViewCellEditingStyle.Delete {
let delegate = UIApplication.sharedApplication().delegate as! AppDelegate
let managedContext = delegate.managedObjectContext!
var error: NSError?
let fetchRequest = NSFetchRequest(entityName: "Task")
let fetchedResults = managedContext.executeFetchRequest(fetchRequest, error: &error) as! [NSManagedObject]
managedContext.deleteObject(fetchedResults[indexPath.row])
table.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)
}
当我运行它时,行可以向左滑动,但没有显示按钮
我补充说:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete", handler: {(action:UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
})
deleteAction.backgroundColor = UIColor.redColor()
return [deleteAction]
}
并删除了CommittedItingStyle中的代码,但仍然没有显示 如果您想要
UITableviewRowAction
,您的委托方法不正确
试试这个
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
}
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let action = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "First") { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
//Do action here
}
action.backgroundColor = UIColor .greenColor()
return [action]
}
截图
问题已解决
我启用了大小类,当我在iPhone6模拟器上运行它时,向左滑动不会显示按钮。但当我将模拟器改为可调整大小的iPhone时,它会显示在右侧 我试过了,但还是有问题。你所说的委托方法是什么意思?我是说
UITableviewRowAction
的委托方法是editactionsforrowatinedxpath
。