我有一個表格視圖,並且我使用UITableViewRowAction
向用戶提供了兩個選項,當在一行上執行滑動操作時,'刪除'和'更多',我希望更多地顯示彈出窗口。 popover需要知道它所錨定的視圖,那麼如何獲得對「更多」按鈕的引用?如何從UITableViewRowAction獲取對按鈕的引用?
我的代碼:
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];
}
此代碼示出了如在錨定小區整體,而不是在「更多」按鈕的酥料餅。
我已經搜索了關於UITableViewRowAction
的文檔,但是沒有任何內容讓我領先。 action
參數的類型也是UITableViewRowAction
,所以我不確定它可以被使用。
更新
根據該意見,我得到了它的工作。我在自定義單元格視圖控制器中調用方法,在那裏訪問子視圖數組。我不喜歡訪問子視圖數組,並假定該數組中的按鈕的位置。
工作代碼:
在tableview中的回調我做的:
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]
(第二subview[1]
在我看來是可行的,因爲我決定它的位置,當我回到[deleteRowAction, moreRowAction]
。
你嘗試顯示moreRowAction按鈕查看aPopover.presentPopoverFromRect(popRect,inView:moreRowAction,permittedArrowDirections:UIPopoverArrowDirection.Any,動畫:真) – Shashi3456643 2015-02-08 10:26:17
它沒有繼承'UIView',所以這是行不通的。我只是嘗試了一些錯誤,我不能使用變量來定義自己,但由於第一個原因,它不應該起作用。 – 2015-02-08 10:34:53
也許你可以找到更多的按鈕的座標位置,並嘗試在UITableViewCell中顯示 – Shashi3456643 2015-02-08 10:49:48