UIPopoverPresentationController来自UITableViewCell中的一个按钮

时间:2014-10-19 12:09:07

标签: ios objective-c uitableview

在我的应用中,我有一个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的左上角,而不是按钮的一侧。 提前谢谢。

1 个答案:

答案 0 :(得分:10)

尝试将sourceView更改为sender

copvc.sourceView = sender;