无法点击 UIAlertAction iPad

UIAlertAction can't be clicked on iPad

我创建了一个带有 3 个 UIAlertAction 的 UIAlertController。它在 iPhone 中运行良好,但我无法在 iPad 中单击任何 UIAlertAction。之前是可以用的,我没有对代码做任何改动

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@“Select Item” message:@“Please choose 1.”                                                                  preferredStyle:UIAlertControllerStyleActionSheet];


[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    _logoView.alpha = 1;
}]];


UIWindow* window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
window.rootViewController = [UIViewController new];
window.windowLevel = UIWindowLevelAlert + 1;

NSString *buttonTitle = [sessionArray objectAtIndex:0];

UIAlertAction *session1 = [UIAlertAction actionWithTitle:buttonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) 
{
    window.hidden = YES;
    [self sessionPickerSelected:0];
}];
[alert addAction:session1];

buttonTitle = [sessionArray objectAtIndex:1];
UIAlertAction *session2 = [UIAlertAction actionWithTitle:buttonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) 
{
    window.hidden = YES;
    [self sessionPickerSelected:1];
}];
[alert addAction:session2];

buttonTitle = [sessionArray objectAtIndex:2];
UIAlertAction *session3 = [UIAlertAction actionWithTitle:buttonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) 
{
    window.hidden = YES;
    [self sessionPickerSelected:2];         
}];
[alert addAction:session3];

[alert setModalPresentationStyle:UIModalPresentationPopover];

UIPopoverPresentationController *popPresenter = [alert popoverPresentationController];
popPresenter.sourceView = _btnLogin;
popPresenter.sourceRect = _btnLogin.bounds;

[window makeKeyAndVisible];
[window.rootViewController presentViewController:alert animated:YES completion:nil];

为了在 iPad 上工作,请使用以下方法

- (void) actionSelect:(UIButton *)sender {


    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Confirm Add Photo"
                                                                   message:@"Are you sure to select photo?"
                                                            preferredStyle:UIAlertControllerStyleActionSheet]; // 1



    UIAlertAction *firstAction = [UIAlertAction actionWithTitle:@"Take Photo"
                                                          style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                                                              NSLog(@"You pressed invitation num ");
                                                              [self dismissViewControllerAnimated:YES completion:nil];
                                                              [self takePhoto:sender];

                                                          }]; // 2
    [alert addAction:firstAction]; // 4


    UIAlertAction *secondAction = [UIAlertAction actionWithTitle:@"Select Photo"
                                                           style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                                                               NSLog(@"You pressed invitation num ");
                                                               [self dismissViewControllerAnimated:YES completion:nil];
                                                               [self selectPhoto:sender];


                                                           }]; // 2
    [alert addAction:secondAction]; // 4


    UIAlertAction *thirdAction = [UIAlertAction actionWithTitle:@"Cancel"
                                                          style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
                                                              NSLog(@"You pressed cancel button ");
                                                          }]; // 3


    [alert addAction:thirdAction]; // 5


    if ([Utility isUserInterfaceiPad]) {
        // Remove arrow from action sheet.
        [alert.popoverPresentationController setPermittedArrowDirections:0];

        //For set action sheet to middle of view.
        alert.popoverPresentationController.sourceView = self.view;
        alert.popoverPresentationController.sourceRect = self.view.bounds;

    }


    [self presentViewController:alert animated:YES completion:nil]; // 6


}

检测iPad

+ (BOOL)isUserInterfaceiPad{

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        //do ur  ipad logic
        return  YES;

    }else
    {
        //do ur  iphone logic
        return NO;

    }

}