【问题标题】:Popover from tableViewCell positioning issue从 tableViewCell 定位问题弹出
【发布时间】:2012-01-28 13:04:47
【问题描述】:

我有一个弹出框,它是从另一个弹出框呈现的。他们都有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];

}

编辑

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

再次返回ArrowDirection = Left

如果我进行了建议的更改(请注意aFrame.size.height * 2 并且没有被二除),箭头指向单元格的中间,但仍然笨拙地定位在新的弹出框中(不是在中间)

【问题讨论】:

    标签: ios ipad uitableview positioning uipopovercontroller


    【解决方案1】:

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

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

    CGRect rectInTableView = [myTableView rectForRowAtIndexPath:someIndexPath];
    

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

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

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

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

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

    我希望此解决方案也适用于您。如果不能随意发表评论,我会看看是否可以进一步帮助您。

    【讨论】:

      【解决方案2】:

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

      1. aFrameheight值更改为aFrame.size.height / 2
      2. 更改presentPopoverFromRect:inView:permittedArrowDirections:animated:,并确保将TableViewCell's contentView 设置为“inView”参数。

      希望这会有所帮助。

      【讨论】:

      • 你最终使用了哪种方式?
      【解决方案3】:

      不知道为什么会这样,但您最好将 (cell.frame.height/2) 添加到弹出框的 frame.y 并修复它:)

      【讨论】:

        【解决方案4】:

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

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

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

        【讨论】:

        • rectForRowAtIndexPath 为 indexPath 上的行返回一个矩形,因此您需要使用 indexPath 作为参数“馈送”它,而不是行...
        猜你喜欢
        • 1970-01-01
        • 2011-04-21
        • 2014-09-21
        • 2015-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-15
        相关资源
        最近更新 更多