[ios8开发指南]iOS8开发弹不出窗体解决办法

更新时间:2019-10-19    来源:ios    手机版     字体:

【www.bbyears.com--ios】

如果用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://www.bbyears.com/shoujikaifa/74183.html

热门标签

更多>>

本类排行