首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能在UIAlertAction上单击iPad

不能在UIAlertAction上单击iPad
EN

Stack Overflow用户
提问于 2017-04-07 08:02:01
回答 1查看 128关注 0票数 0

我用3 UIAlertController创建了一个UIAlertAction。它在iPhone中运行良好,但我不能在iPad中的任何UIAlertAction中单击。以前它是工作的,我没有在代码中做任何修改

代码语言:javascript
复制
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];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-07 08:30:13

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

代码语言:javascript
复制
- (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

代码语言:javascript
复制
+ (BOOL)isUserInterfaceiPad{

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

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

    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43272824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档