2015-09-06 29 views
13

嗨有什么办法打开UIPresentationController时,左刷卡被触发,它是点击EditSwift - UITableView editActionsForRowAtIndexPath打开UIPresentationController时点击编辑

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 
     let delete = .... 
     let edit = UITableViewRowAction(style: .Normal, title: "Edit") { action, index in 
      //OPEN UIPresentationController HERE 
     } 
     return [delete, edit] 
} 

回答

7

与@patchdiaz相同,我不是100%确定你想要做什么。然而,这个代码块可能足以进行定制,以实现自己的目标:

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? { 
    let edit = UITableViewRowAction(style: .Normal, title: "Edit") { action, index in 
     // OPEN UIPresentationController HERE 
     let vc = UIViewController(nibName: nil, bundle: nil) 
     vc.view.frame = CGRect(x: 0, y: 0, width: 100, height: 200) 
     vc.view.backgroundColor = UIColor.orangeColor() 
     vc.modalPresentationStyle = .Popover 

     let popover = vc.popoverPresentationController! 
     let cell = tableView.cellForRowAtIndexPath(indexPath)! 

     var cellAbsolutePosition = cell.superview!.convertPoint(cell.frame.origin, toView: nil) 
     cellAbsolutePosition.x = cell.frame.width - 60 
     popover.sourceRect = CGRect(origin: cellAbsolutePosition, size: cell.frame.size) 
     popover.sourceView = tableView 

     self.presentViewController(vc, animated: true, completion: nil) 
    } 
    return [edit] 
} 

它会显示一个酥料饼就在这样的“编辑”按钮位置:

enter image description here

+0

我说这只是一个例子,如何做到这一点,足够的定制:)请做其余的,因为我相信你知道如何使它 – Ducky

+0

我不能修复附近的箭头编辑,我不知道如何设置高度对于我用作故事板的vc –

+0

老兄,这是完全不同的问题。如果您希望人们更高效地帮助您,请提供更多详细信息。 – Ducky

2

不知道你在问什么。像这样的东西应该工作(这是在斯威夫特2):

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> 
     [UITableViewRowAction]? { 
      let delete = ... 
      let edit = UITableViewRowAction(style: .Normal, title: "Edit") { [weak self] _ in 
       let viewController = ... 
       viewController.modalPresentationStyle = .Custom 
       self?.presentViewController(viewController, animated: true, completion: nil) 
      } 
      return [delete, edit] 
    } 
相关问题