2016-07-06 10 views
1

Я использую следующий код, чтобы показать UIAlertController на toolBarButtonItem,UIAlertController показано на BarButtonItem не центрируется правильно

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; 

    [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 
    }]];  

    [alertController addAction:[UIAlertAction actionWithTitle:@"Delete Selected Accounts" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { 
     [Utility showAlertWithTitle:nil message:DELETE_ACCOUNT delegate:self tag:1 buttons:@[@"Cancel", @"Delete"]]; 
    }]]; 
    alertController.popoverPresentationController.barButtonItem = self.moreButtonItem; 
    [self presentViewController:alertController animated:YES completion:nil]; 

alertController показано с помощью этого кода появляется правосторонний не по центру. Я хочу, чтобы alertController отображался точно в центре по сравнению с инструментом toolBarButtonItem.

+1

Попробуйте использовать 'alertController.popoverPresentationController.sourceRect' и' alertController.popoverPresentationController.sourceView' вместо barbutton –

ответ

0

попробуйте добавить ниже код

alertController.popoverPresentationController.sourceView = senderView; //your view 
alertController.popoverPresentationController.sourceRect = senderView.bounds; //your view 
alertController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionAny; 

Это фиксированная моя проблема.

+0

Большое спасибо за вашу помощь. – Nikhil

+0

@ Нихиль вы можете возвысить как оценку;) –