LoginSignup
5
5

More than 5 years have passed since last update.

iPadでUIAlertControllerが落ちる場合は

Posted at

こんな感じでUIAlerControllerを表示した場合

-(void)pushButton:(id)sender {

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Title",@"") message:NSLocalizedString(@"Message",@"") preferredStyle:UIAlertControllerStyleActionSheet];

    [alertController addAction:[UIAlertAction actionWithTitle:@"Action1" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    //ボタンが押された時の処理
    }]];


    [self presentViewController:alertController animated:YES completion:nil];
}

だとiPadだとクラッシュするので、

alertController.popoverPresentationController.sourceView = self.view;
alertController.popoverPresentationController.sourceRect = ((UIButton *)sender).frame;

という感じで、presentViewControllerの前に呼んで上げる必要があります。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5