如果用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];
    }
}


参考页面: http://stackoverflow.com/questions/24942282/uiimagepickercontroller-not-presenting-in-ios-8





原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
发表评论
AD
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML 打开UBB 打开表情 隐藏
昵称   密码   游客无需密码
网址   电邮   [注册]
               

验证码 不区分大小写
 

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐