ios - 来自 UITableViewCell 中的按钮的 UIPopoverPresentationController

标签 ios objective-c uitableview

在我的应用程序中,我有一个 UITableView,它的一个单元格中有一个 UIButton。这个按钮有一个 Action :

    - (IBAction)showPopover:(UIButton *)sender    
{
    ChoseOptionsViewController *contentController = [[ChoseOptionsViewController alloc] init];
    contentController.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *copvc = contentController.popoverPresentationController;
    copvc.permittedArrowDirections = UIPopoverArrowDirectionAny;
    copvc.sourceView = self.view;
    copvc.sourceRect = sender.bounds;
    contentController.preferredContentSize = CGSizeMake(200, 200);
    [self presentViewController:contentController animated:YES completion:nil];
}

问题在于 sender.bounds 不返回任何内容,因此弹出窗口显示在 self.view 的左上角,而不是按钮的旁边。 提前致谢。

最佳答案

尝试将您的 sourceView 更改为 sender:

copvc.sourceView = sender;

关于ios - 来自 UITableViewCell 中的按钮的 UIPopoverPresentationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26450331/

相关文章:

iOS为uitableviewcell添加自定义属性

ios - 如何删除 UITableViewCell NSIBPrototypingLayoutConstraint 并将我自己的添加到 subview ?

ios - 如何将自动布局与容器转换一起使用?

ios - 具有两个自定义单元格的 TableView 导致单元格重用问题(Swift 4)

objective-c - 我如何使用 UIPageControl?

ios - 使用委托(delegate)清理数组

ios - 在 ios 中延迟加载图像?

ios - 在 Phonegap 中,HTML 不会随着应用程序的旋转而调整大小

ios - 为什么返回按钮无法从 ViewController 返回?

objective-c - NSTimer的内存管理——是否需要分配给变量?