UIPopoverController通过UITableViewCell

Ash*_*raf 3 iphone uitableview ipad uipopovercontroller ios

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

当表没有滚动时,此代码工作正常,对于滚动表视图,弹出箭头定位不正确.

[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];
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

Dav*_*eck 6

您应该将单元格作为视图传递.很可能你会想要传递rect的单元格边界(cell.bounds,而不是cell.frame).


man*_*yvw 5

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

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

[popoverController presentPopoverFromRect:rect
    inView:tableView
    permittedArrowDirections:UIPopoverArrowDirectionAny
    animated:YES];
Run Code Online (Sandbox Code Playgroud)