来自uitableViewCell定位问题的popover

时间:2011-12-27 13:54:02

标签: ios ipad uitableview positioning uipopovercontroller

我有另一个popover提供的popover。他们都有tableViews。第一行的第二个弹出框很好,箭头指向单元格的中间。但其他人指向牢房的顶部,箭头位于弹出窗口的顶部,而不是在中间......

这就是我如何构建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而不是除以2),箭头指向单元格的中间位置,但仍然位于新的弹出框架中(不在中间)

enter image description here

4 个答案:

答案 0 :(得分:4)

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

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

CGRect rectInTableView = [myTableView rectForRowAtIndexPath:someIndexPath];

这很有用,但不是完整的故事(至少不适合我)。您可能希望将该矩形转换为视图,以获得该矩形实际上很重要。

第二种方法会将此rect转换为您想要弹出窗口的视图的透视图。在我的情况下[myTableView superView],但它可以是任何可见的视图。

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

这个rec​​tInSuperView可能就是你所寻求的。它解决了很多我的cellFrame问题,它也可能对你有帮助。

箭头总是指向一个矩形的中间位置,所以如果你的矩形工作不正常,“黑客”矩形以使其符合你的需要并不是解决这个问题的最佳方法。

我希望这个解决方案也适合你。如果没有随意发表评论,我会看看我是否可以帮助你。

答案 1 :(得分:2)

我认为这个问题有两种可能的解决方案:

  1. height的{​​{1}}值更改为aFrame
  2. 更改aFrame.size.height / 2:,并确保将presentPopoverFromRect:inView:permittedArrowDirections:animated TableViewCell's设置为“contentView”参数。
  3. 希望这有帮助。

答案 2 :(得分:1)

您需要确定行调用popover的内容。执行此操作后,尝试将CGRect aFrame = [self.tableView rectForRowAtIndexPath:indexPath];替换为

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

编辑:修复代码以反映实际解决方案

答案 3 :(得分:1)

无法理解为什么会发生这种情况,但您也可以将(cell.frame.height / 2)添加到popover的frame.y并修复它:)

相关问题