【问题标题】:Performing a segue control with UITableViewRowAction使用 UITableViewRowAction 执行 segue 控制
【发布时间】: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


【解决方案1】:

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

【讨论】:

  • 当我尝试您的解决方案时,我收到 mainVC 无法将类型的值转换为 CustomTableViewCell 的错误。一个多星期以来,我一直在尝试解决此问题,但似乎没有任何效果。
猜你喜欢
  • 1970-01-01
  • 2019-01-21
  • 1970-01-01
  • 1970-01-01
  • 2016-12-31
  • 1970-01-01
  • 2014-11-23
  • 2012-06-02
  • 1970-01-01
相关资源
最近更新 更多