Я использую объектив-c написать о UIAlertControllerStyleActionSheet
из UIAlertcontroller
.iOS popover show дважды будет разбиваться
Я хочу показать предупреждающий лист на iPhone и popoverPresentationController
на iPad.
Во-первых, я установил делегата UIPopoverPresentationControllerDelegate
.
Когда я нажимаю на свою кнопку, всплывающее окно отображается правильно.
Но я нажимаю на экран, закрывая popover. он покажет предупреждение ниже.
[Предупреждение] < _UIPopoverBackgroundVisualEffectView 0x14be52ef0> спрашивается анимировать его непрозрачность. Это приведет к тому, что эффект будет искажен до тех пор, пока непрозрачность не вернется к 1.
Теперь, когда я нажимаю кнопку, снова отображается всплывающее окно.
Это приведет к сбою в работе ниже журнала.
Нагрузочное приложение из-за неперехваченное исключение «NSGenericException», причина: «Ваша заявка представлена UIAlertController() стиль UIAlertControllerStyleActionSheet. ModalPresentationStyle UIAlertController с этим стилем - UIModalPresentationPopover. Вы должны предоставить информацию о местоположении для этого popover через popoverPresentationController контроллера контролера. Вы должны указать либо sourceView, и sourceRect, либо barButtonItem. Если эта информация неизвестна при представлении контроллера предупреждений, вы можете предоставить ее в методе UIPopoverPresentationControllerDelegate -prepareForPopoverPresentation. ' *** Первый стек бросить вызов: (0x18d9a41c0 0x18c3dc55c 0x19418a8b0 0x193ac60a8 0x193ac3df4 0x193a08d0c 0x1939faac0 0x19376a22c 0x18d9517dc 0x18d94f40c 0x18d94f89c 0x18d87e048 0x18f2ff198 0x1937e2b50 0x1937dd888 0x10011198c 0x18c8605b8) LibC++ abi.dylib: оканчивающиеся неперехваченного исключением типа NSException
Кто-нибудь знает, как решить проблему?
Мой код ниже:
@interface ViewController() <...UITextViewDelegate,UITextFieldDelegate...> {
UIAlertController *alertTypeAlertController;
UIAlertAction *alertType1Action;
UIAlertAction *alertType2Action;
UIPopoverPresentationController *popPresenter;
}
- (void)viewDidLoad {
[super viewDidLoad];
alertTypeAlertController = [UIAlertController
alertControllerWithTitle:@"selecte one:"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
alertType1Action = [UIAlertAction
actionWithTitle:@"Type1"
style:UIAlertActionStyleDefault
handler:nil];
alertType2Action = [UIAlertAction
actionWithTitle:@"Type2"
style:UIAlertActionStyleDefault
handler:nil];
[alertTypeAlertController addAction: alertType1Action];
[alertTypeAlertController addAction: alertType2Action];
// for ipad
popPresenter = [alertTypeAlertController popoverPresentationController];
popPresenter.permittedArrowDirections = UIPopoverArrowDirectionLeft;
popPresenter.delegate = self;
popPresenter.sourceView = self.theTypeBtn;
popPresenter.sourceRect = CGRectMake(230, 22, 10, 10);
....
}
- (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController {
// called when a Popover is dismissed
}
- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController {
// return YES if the Popover should be dismissed
// return NO if the Popover should not be dismissed
return YES;
}
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}
enter code here
Большое спасибо.
Я пытаюсь добавить __weak перед «UIPopoverPresentationController * popPresenter», результат по-прежнему показывают ту же ошибку. :( – dickfala
проверка второй поп если self.presentedViewController отсутствует, обычно приложение падает, если вы пытаетесь представить 2 –
Я проверяю кнопку первого щелчка, поп - nil (self.presentedViewController), но он показывает правильное, приложение не падает. Но нажмите вторую кнопку, поп-прежнему нет, приложение вылетает. @@ – dickfala