ios - 来自 tableViewCell 定位问题的 Popover

标签 ios ipad uitableview positioning uipopovercontroller

我有一个从另一个弹出窗口显示的弹出窗口。他们都有 tableView。第一行的第二个弹出窗口很好,箭头指向单元格的中间。但是其他的都指向cell的顶部,箭头是在popover的顶部,而不是在中间……

这就是我构建弹出窗口的方式

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{

self.editController = [[TitleViewController alloc] init];
[self.editController setSizeWithWidth:self.view.bounds.size.width AndHeight:140.0];
self.editController.directoryString = [directoryPath stringByAppendingPathComponent:[self.tableView cellForRowAtIndexPath:indexPath].textLabel.text];

self.editPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.editController];



CGRect aFrame = [self.tableView rectForRowAtIndexPath:indexPath];

[self.editPopoverController presentPopoverFromRect:aFrame inView:self.tableView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

} Here is the misplaced second popover

编辑

如果我将箭头方向更改为 Any,它看起来像这样。

再次返回 ArrowDirection = Left

如果我按照建议进行更改(注意 aFrame.size.height * 2 而不是除以二),箭头指向单元格的中间,但位置仍然很尴尬在新的弹出框架中(不在中间)

enter image description here

最佳答案

在尝试将单元格扩展到整个 tableView 大小时,我实际上遇到了一些相同的问题。询问单元格框架并在 tableview 之外使用它并不像我想象的那么容易。然而,在向先生提出一些直接问题后,我找到了解决方案。谷歌。

第一种方法实际上会从 tableView 的角度给出单元格的框架。

CGRect rectInTableView = [myTableView rectForRowAtIndexPath:someIndexPath];

这很有用,但不是完整的故事(至少不适合我)。如果拥有该矩形真的很重要,您可能希望将该矩形转换为 View 。

第二种方法会将此矩形转换为您希望弹出框所在的 View 的透视图。在我的例子中 [myTableView superView] 但它可以是任何可见的 View 。

CGRect rectInSuperview = [myTableView convertRect:rectInTableView toView:someView];

这个 rectInSuperView 可能就是您要找的。它解决了我的很多 cellFrame 问题,也可能对您有所帮助。

箭头将始终指向矩形的中间,因此如果您的矩形无法正常工作,“修改”矩形使其满足您的需求并不是解决此问题的最佳方法。

我希望这个解决方案也适用于您。如果没有,请随时发表评论,我会看看是否可以进一步帮助您。

关于ios - 来自 tableViewCell 定位问题的 Popover,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8645388/

相关文章:

ios - 自动布局 : Y Position as the Max of Two Values

ios - 我如何检查 url 字符串是否包含 swift 中的单词?

iphone - 来自一组图像的视频有 RGB 问题

ios - 根据 iPhone 屏幕尺寸增加字体大小

ios - 我在 View 类中编写了一个tableView,但它无法显示数据源

iphone - UITableView部分索引背景?

objective-c - 如何实现在一个部分中点击一个 UITableViewCell 导航到多个 UITableViewCells 以获取详细信息?

iphone - 如何使用文件名中带有空格的自定义字体文件

ios - SceneView 和场景 isPlaying、isPaused

ios - 在 UIButton 上加载 UISplitViewController 单击