iOS8开发弹不出窗体解决办法

在ios8应用开发的时候出现窗体弹不出的现象,提示错误:Warning: Attempt to present on xxxx which is already presenting (null),现在来看解决方法。

如果用actionSheet问用户选项,然后选择做啥

UIActionSheet *actionSheet= [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"从相片库选取", nil];
    [actionSheet showInView:self.view];


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    selectedIndex = buttonIndex;
        if (selectedIndex == 0) {
            [self addCarema];
        }else if (selectedIndex == 1){
            [self openPicLibrary];
        }
}


openPicLibrary唤不起窗体,会有错误

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:picker animated:YES completion:^{
        }];


比如类似错误

Warning: Attempt to present   on xxxx which is already presenting (null)

参考解决方式:

引用
I think this is because in iOS 8, alert views and action sheets are actually presented view controllers (UIAlertController). So, if you're presenting a new view controller in response to an action from the UIAlertView, it's being presented while the UIAlertController is being dismissed. I worked around this by delaying the presentation of the UIImagePickerController until the next iteration of the runloop, by doing this:


[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    [self openPhotoPicker:sourceType];
}];


本例的解决办法是:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    selectedIndex = buttonIndex;
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        if (selectedIndex == 0) {
            [self addCarema];
        }else if (selectedIndex == 1){
            [self openPicLibrary];
        }
    }];
}


或者是记下点击的index,在动画结束的时候处理:

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (selectedIndex == 0) {
        [self addCarema];
    }else if (selectedIndex == 1){
        [self openPicLibrary];
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值