UIPopoverPresentationController using button in UITableViewCell

In my application I have UITableView

, and in one cell there is UIButton

. 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 it sender.bounds

doesn't return anything, so the poper is displayed in the upper left corner self.view

, not next to the button. Thanks in advance.

+3


source to share


1 answer


Try changing sourceView

to sender

:



copvc.sourceView = sender;

      

+10


source







All Articles