在我的应用中,我有一个UITableView
,其中一个单元格中有一个UIButton
。此按钮有一个操作:
- (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
的左上角,而不是按钮的一侧。
提前谢谢。
答案 0 :(得分:10)
尝试将sourceView
更改为sender
:
copvc.sourceView = sender;