I know that this is old school question - but I did searched the web and found solutions to be deprecated. How would I implement a UIAlertcontroller as popOver(with arrow direction up) in a barButton. Here's the code:
- (IBAction)eventSortingAction:(UIBarButtonItem *)sender {
UIAlertController * view= [UIAlertController
alertControllerWithTitle:@"My Title"
message:@"Select you Choice"
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//Do some thing here
[view dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
[view dismissViewControllerAnimated:YES completion:nil];
}];
[view addAction:ok];
[view addAction:cancel];
[view setModalPresentationStyle:UIModalPresentationPopover];
view.modalInPopover = YES;
view.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
view.popoverPresentationController.delegate = self;
[self presentViewController:view animated:YES completion:nil];
UIView* senderView = [sender valueForKey:@"view"]; //HACK
UIPopoverPresentationController* popover = view.popoverPresentationController;
if (popover) {
popover.sourceView = senderView;
popover.sourceRect = senderView.bounds;
popover.permittedArrowDirections = UIPopoverArrowDirectionUp;
popover.barButtonItem = self.actionBarButton;
popover.delegate = self;
}}
apparently I always got a "popover = nil". Please Help! Thanks in advance!
By the way this code is not mine, just testing it in Xcode.