美文网首页
iOS Ipad UIAlertController 崩溃解决方

iOS Ipad UIAlertController 崩溃解决方

作者: 透支未来 | 来源:发表于2017-09-28 15:41 被阅读339次

    兼容ipad的 UIAlertController

    
    -(void)showSheet:(SYUser *)user IndexPath:(NSIndexPath *)indexPath{
        
        SYUser *loginUser=[SYUser sharedLoginUser];
        if (loginUser.userRole !=UserRoleEosAdmin) {
            return;
        }
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle: UIAlertControllerStyleActionSheet];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:WYLocalizedString(@"co_cancel", @"") style:UIAlertActionStyleCancel handler:nil];
        
        WS(ws)
        UIAlertAction *archiveAction=[UIAlertAction actionWithTitle:WYLocalizedString(@"co_delete", @"") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [ws userDelete:user];
        }];
        
        NSString *frozenTitle=@"";
        if (user.status==2) {
            frozenTitle=[NSString stringWithFormat:@"%@",WYLocalizedString(@"co_frozen", @"")];
        }else{
            frozenTitle=[NSString stringWithFormat:@"%@",WYLocalizedString(@"co_unfreeze", @"")];
        }
        
        UIAlertAction *frozenAction = [UIAlertAction actionWithTitle:frozenTitle style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            [ws doFrozen:user];
        }];
        
        [alertController addAction:frozenAction];
        if (user.status==1) {
            [alertController addAction:archiveAction];
        }
        [alertController addAction:cancelAction];
        //核心代码. 兼容ipad
        if ([SYAboutDevice currentDeviceType] == UIUserInterfaceIdiomPad) {
            
            CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:indexPath];
            CGRect rectInSuperView = [self.tableView convertRect:rectInTableView toView:[self.tableView superview]];
            
            UIPopoverPresentationController *popPresenter = [alertController popoverPresentationController];
            popPresenter.sourceView =[self.tableView superview];
            popPresenter.sourceRect =rectInSuperView;
            popPresenter.permittedArrowDirections = UIPopoverArrowDirectionUp;
            [self presentViewController:alertController animated:YES completion:nil];
        }else{
            
            [self presentViewController:alertController animated:YES completion:nil];
        }
    }
    
    

    判断设备是ipad 还是iphone

    
    +(UIUserInterfaceIdiom)currentDeviceType{
        if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPad){
            return UIUserInterfaceIdiomPad;
        }else{
            return UIUserInterfaceIdiomPhone;
        }
    }
    
    

    相关文章

      网友评论

          本文标题:iOS Ipad UIAlertController 崩溃解决方

          本文链接:https://www.haomeiwen.com/subject/owxvextx.html