2016-07-06 75 views
1

我使用以下代碼來顯示UIAlertController上的toolBarButtonItem,使用該代碼所示UIAlertController不居中正確

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

@Nikhil你可以讚賞作爲一種欣賞;) –