[英]Cancel button is not showing for a UIAlertController in iPad, iOS8 and in objective-C
我正在嘗試使用UIAlertController。 我需要一個帶有兩個按鈕的彈出框 - “取消”和“刪除並退出”。 但我只能看到“刪除並退出”按鈕而不是取消按鈕。 這是代碼: -
NSString *confirmText = "Hi";
UIAlertController *alert = [UIAlertController alertControllerWithTitle:confirmText message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
// Created a deleted action
UIAlertAction *destroyAction = [UIAlertAction actionWithTitle:@"Delete and Sign Out"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
NSLog(@"Delete Action Pressed");
[self signout];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:nil];
[alert.view setTintColor:[UIColor grayColor]];
[alert addAction:cancelAction];
[alert addAction:destroyAction];
[alert setModalPresentationStyle:UIModalPresentationPopover];
UIPopoverPresentationController *popPresenter = [alert popoverPresentationController];
// Set the sourceView.
popPresenter.sourceView = logoutButton;
popPresenter.sourceRect = logoutButton.bounds;
[self presentViewController:alert animated:YES completion:nil];
不幸的是,我無法發布圖片,所以如果您需要更多說明,請告訴我。
在iOS8上,僅在需要時顯示取消按鈕。 如果您在iPhone上運行應用程序,則可見。 如果您在iPad上運行應用程序,則不顯示取消按鈕,並且當用戶點擊彈出窗口外時,將調用取消操作的處理程序(樣式:UIAlertActionStyleCancel)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.