gpt4 book ai didi

swift - 使用 UITableViewRowAction 执行 segue 控制

转载 作者:搜寻专家 更新时间:2023-11-01 05:39:54 26 4
gpt4 key购买 nike

如果在 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]
}

最佳答案

我认为您需要在操作代码中调用 performSegueWithIdentifier 函数,然后 prepareForSegue 将在移动到下一个 viewController 之前自动被调用>

关于swift - 使用 UITableViewRowAction 执行 segue 控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31908991/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com