我想将Popover设置在单元格标签的右边,但它当前位于左上方。如何更改它以使其处于正确的位置?

我使用以下方法创建自定义单元:

var currentCell:CustomTableViewCell = tableView.cellForRowAtIndexPath(indexPath) as CustomTableViewCell;

并使用以下命令在桌面水龙头上加载弹出窗口:
var popoverContent = ModalTableViewController()
var nav = UINavigationController(rootViewController: popoverContent)
nav.modalPresentationStyle = UIModalPresentationStyle.Popover

var popover = nav.popoverPresentationController as UIPopoverPresentationController
popoverContent.preferredContentSize = CGSizeMake(500,400);
popover.delegate = self
popover.sourceView = self.view
popover.sourceRect = currentCell.labelCellTitle.bounds
labelCellTitle是我单元格中的自定义标签。我想向该标签显示带有箭头的Popover。我的代码有什么问题?有任何想法吗?

最佳答案

由于popoverview需要知道要显示的视图和rect区域的框架,因此应使用如下所示

var popover = nav.popoverPresentationController as UIPopoverPresentationController
popoverContent.preferredContentSize = CGSizeMake(500,400);
popover.delegate = self
popover.sourceView = currentCell.labelCellTitle.superView
popover.permittedArrowDirections = UIPopoverArrowDirectionRight
popover.sourceRect = currentCell.labelCellTitle.frame

关于ios - UIPopover在单元格中的位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25182700/

10-09 16:24
查看更多