【问题标题】:UIPopoverController over UITableViewCellUITableViewCell 上的 UIPopoverController
【发布时间】:2011-04-18 15:58:43
【问题描述】:

我想以编程方式在表格视图中选择一行,然后显示我的弹出框并让箭头指向单元格。

当表格没有滚动时,此代码可以正常工作,对于滚动表格视图,弹出箭头的位置不正确。

[self.EventsTableView selectRowAtIndexPath:indexPath 
                                  animated:YES 
                            scrollPosition:UITableViewScrollPositionMiddle];

[popoverController presentPopoverFromRect:CGRectOffset(cell.frame, 0, cell.frame.size.height + self.EventsTableView.contentOffset) 
                                   inView:self.view      
                 permittedArrowDirections:UIPopoverArrowDirectionLeft 
                                 animated:YES];

感谢您的帮助

【问题讨论】:

    标签: iphone ios ipad uitableview uipopovercontroller


    【解决方案1】:

    您应该将单元格作为视图传递。您很可能希望为矩形传递单元格的边界(cell.bounds,而不是 cell.frame)。

    【讨论】:

    • 正确,很好的答案简单地说:[popoverController presentPopoverFromRect:cell.bounds inView:cell allowedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];谢谢。
    • 我仍然需要处理不可见的行!
    • 您的意思是当一个单元格以不可见的方式滚动时?在这种情况下,您可能希望使用 scrollToRowAtIndexPath:atScrollPosition:animated: 将其移至视图中。
    【解决方案2】:

    当用户向下滚动列表时,上述方法似乎对我不起作用。找到相对于滚动量的单元格位置是诀窍。

    CGRect rect = [tableView convertRect:[tableView rectForRowAtIndexPath:indexPath]
        toView:tableView]; 
    
    [popoverController presentPopoverFromRect:rect
        inView:tableView
        permittedArrowDirections:UIPopoverArrowDirectionAny
        animated:YES];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-15
      • 1970-01-01
      • 1970-01-01
      • 2013-05-04
      • 1970-01-01
      • 2011-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多