一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

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

时间:2015-04-11 编辑:简简单单 来源:一聚教程网

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

热门栏目