在我的应用程序中,我有一个 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/