Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPopoverPresentationController from a button in UITableViewCell

In my app I've got a UITableView and one cell of it has a UIButton in it. This button has an 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];
}

The problem is that sender.bounds returns nothing so the popover is shown in the upper left corner of self.view, not by the side of the button. Thanks in advance.

like image 338
piligreem Avatar asked Dec 25 '22 03:12

piligreem


1 Answers

Try changing your sourceView to sender:

copvc.sourceView = sender;
like image 118
pbasdf Avatar answered Dec 28 '22 08:12

pbasdf