swift - 使用 UITableViewRowAction 执行 segue 控制

标签 swift cocoa-touch core-data ios8 uitableviewrowaction

如果在 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/

相关文章:

iphone - View Controller 的 viewDidLoad 方法在 applicationDidFinishLaunching 之前完成

iphone - UIScrollView 后面的 UIButton

ios - UIAlertAction 值列表

ios - 一个 View Controller 中具有不同重用单元格的两个 Collection View

iPhone应用程序分发构建包含一个错误

iphone - 核心数据/NSFetchedResultsController错误

ios - 从可能损坏的核心数据数据库中恢复

iphone - 将模型层基于 NSManagedObject 的负面后果是什么(如果有的话)?

ios - 数据库存在于模拟器中但不存在于设备构建中(将文件从 App Bundle 复制到 Swift 中的文档目录)

xcode - 使用 Swift (Xcode 6) 更改 BarButtonItem 字体