UIPopoverController 通过 UITableViewCell

发布于 2024-11-02 06:16:35 字数 623 浏览 5 评论 0原文

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

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

[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];

感谢您的帮助

I'd like to programmatically select a row in a table view then present my popover and let the arrow points to the cell.

This code works fine when the table has no scrolling, for scrolling table view the popover arrow is positioned incorrectly.

[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];

Thanks for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一城柳絮吹成雪 2024-11-09 06:16:35

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

You should pass the cell as the view. Most likely you will want to pass the cell's bounds (cell.bounds, not cell.frame) for the rect.

一杆小烟枪 2024-11-09 06:16:35

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

CGRect rect = [tableView convertRect:[tableView rectForRowAtIndexPath:indexPath]
    toView:tableView]; 

[popoverController presentPopoverFromRect:rect
    inView:tableView
    permittedArrowDirections:UIPopoverArrowDirectionAny
    animated:YES];

Above method didn’t seem to work for me when once the user scrolls the list down. Finding the cell position relative to the scrolled amount was the trick.

CGRect rect = [tableView convertRect:[tableView rectForRowAtIndexPath:indexPath]
    toView:tableView]; 

[popoverController presentPopoverFromRect:rect
    inView:tableView
    permittedArrowDirections:UIPopoverArrowDirectionAny
    animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文