【发布时间】:2015-08-09 21:24:56
【问题描述】:
如果在 mainVC 中点击自定义 UITableViewCell 时应用程序正常工作,我可以在 inputTableVC 中编辑 CoreData。 现在我正在尝试做同样的事情,但是当点击 UITableViewRowAction“编辑”时。 “删除”功能已经开始工作了。
有没有办法在 UITableViewRowAction 中实现 prepereForSegue 或 fetchRequest ?
提前致谢。
// Mark- My current working Segue code
override public func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "EditRaptor" {
let customMainVCTableCell = sender as! CustomMainVCTableCell
let indexPath = tableView.indexPathForCell(customMainVCTableCell)
let addRaptorVC:AddRaptorVC = segue.destinationViewController as! AddRaptorVC
let addRaptor:AddRaptorCoreData = fetchedResultController.objectAtIndexPath(indexPath!) as! AddRaptorCoreData
addRaptorVC.addRaptor = addRaptor
}
}
// Mark- The TableViewRowAction that needs to be fixed
public func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let managedObject:NSManagedObject = fetchedResultController.objectAtIndexPath(indexPath) as! NSManagedObject
var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete" , handler: {
(action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
self.managedObjectContext?.deleteObject(managedObject)
self.managedObjectContext?.save(nil)
})
var editAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Edit" , handler: {
(action:UITableViewRowAction!, indexPath:NSIndexPath!) in
})
return [deleteAction,editAction]
}
【问题讨论】:
-
所以您想对编辑操作执行转场?
-
是的...我喜欢执行与点击特定 tableViewCell 时相同的操作,然后转到下一个 viewController 来编辑数据。所以现在我可以用 prepareForSegue 函数来做到这一点。但是当我在操作代码中调用它时,那不起作用。
-
请检查我的回答,如果有效,请接受。
标签: swift cocoa-touch core-data ios8 uitableviewrowaction