如何获得从UITableViewRowActionbutton的引用?

我有一个表视图,我使用UITableViewRowAction向用户提供了两个选项,当一个刷卡完成行,'删除'和'更多',我希望更多显示一个popup窗口。 popup窗口需要知道它所锚定的视图,那么如何获得对“更多”button的引用呢?

我的代码:

 func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? { var moreRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "More", handler:{action, indexpath in let p = SomeViewController(aClient: client) let aPopover = UIPopoverController(contentViewController: p) let popRect = self.view.frame // What should x be? let x: UIView = self.tableView.cellForRowAtIndexPath(indexPath)! aPopover.presentPopoverFromRect(popRect, inView: x, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true) }); var deleteRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete", handler:{action, indexpath in // Do something to delete. }); return [deleteRowAction, moreRowAction]; } 

这段代码将popup窗口显示为锚定在整个单元格上,而不是“更多”button。

我已经search了有关UITableViewRowAction的文档,但是没有任何内容给我带来了领先。 action参数的types也是UITableViewRowAction所以我不确定它可以被使用。


更新

根据评论,我得到了它的工作。 我在自定义单元格视图控制器中调用一个方法,在那里我访问子视图数组。 我不喜欢访问子视图数组,并假设该数组中的button的位置。

工作代码:

在tableviewcallback中,我这样做:

 func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? { var moreRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Plus", handler:{action, indexpath in let cell = self.tableView.cellForRowAtIndexPath(indexPath)! as MyCell cell.showPopover() }); 

里面MyCell我做:

 func showPopover() { let p = ClientLongPressViewController(client: self.client) let aPopover = UIPopoverController(contentViewController: p) let x: UIView = self.subviews[0].subviews[1] as? UIView ?? self let popRect = x.frame aPopover.setPopoverContentSize(CGSize(width: 215, height: 241), animated: true) aPopover.presentPopoverFromRect(popRect, inView: x, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true) } 

我试过(在MyCell内)来访问self.contentView但这只包含主单元格视图中的元素,而不是滑动元素。
还尝试使用self.editingAccessoryView ,但它是零。

所以我仍然想要一个更好的方式来获得“删除确认视图”,我现在访问self.subviews[0] (第二self.subviews[0] subview[1]在我看来是好的,因为我决定它的位置,当我返回[deleteRowAction, moreRowAction]

似乎没有任何直接的方式访问button本身,但是当你滑过单元格后,我相信会发生什么,是单元格被移动到左边,并且一个名为UITableViewCellDeleteConfirmationView的新视图被添加到对。 所以,如果将popup窗口放在单元格原点加上其宽度,它将位于单元格的右边缘,这将位于button的左侧(假设您的button是最左边的那个,如果有多个纽扣)。

 var moreRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "More", handler:{action, indexpath in let p = SomeViewController(aClient: client) let aPopover = UIPopoverController(contentViewController: p) let cell: UITableViewCell = self.tableView.cellForRowAtIndexPath(indexPath)! let popRect = CGRectMake(cell.frame.origin.x + cell.frame.size.width, cell.frame.size.height/2.0, 1, 1); aPopover.presentPopoverFromRect(popRect, inView: cell, permittedArrowDirections: .Right, animated: true) });