Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

presenting UIAlertController from a toolbar button

Dumb question - but how do I present an UIAlertController (popover) from a toolbar button? Previously (with UIAlertView) I'd simply call showFromBarButtonItem: but this doesn't appear to be possible with the UIAlertController.

I have a workaround - as below - but it's a bit 'risky'

    UIView* senderView = [sender valueForKey:@"view"]; //HACK
    UIPopoverPresentationController* popover = alertController.popoverPresentationController;
    if (popover)
    {
        popover.sourceView = senderView;
        popover.sourceRect = senderView.bounds;
        popover.permittedArrowDirections = UIPopoverArrowDirectionAny;
    }

(sender is a UIBarButtonItem)

like image 703
Scotty Avatar asked Sep 23 '14 10:09

Scotty


1 Answers

Try to setpopover.barButtonItem

like image 154
Dirk Avatar answered Dec 07 '22 20:12

Dirk