简体   繁体   English

在演示过程中尝试在UITabBarController上呈现UIImagePickerController

[英]Attempt to present UIImagePickerController on UITabBarController while a presentation is in progress

I need help for resolving a warning error. 我需要解决警告错误的帮助。 I use a UIImagePickerController and it's showing when I tap on the third tab on my tabBar. 我使用UIImagePickerController ,当我在tabBar的第三个选项卡上点击时会显示它。 When I cancel, I want to show the last tab before the selection of the camera, but when I dismiss my picker, I get a warning!! 取消时,我想在选择相机之前显示最后一个标签,但是当我取消选择器时,会收到警告!!

This is my code and I don't understand why I get the warning... 这是我的代码,我不明白为什么会收到警告...

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self showPickerController];
}


- (void) showPickerController
{
    imagePicker = [[UIImagePickerController alloc] init];
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.delegate = self;
    } else{
        UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Erreur !"
                                                          message:@"Votre iPhone n'a pas de Camera"
                                                         delegate:self
                                                cancelButtonTitle:@"Ok"
                                                otherButtonTitles:nil];
        [message show];
    }
    [self presentViewController:imagePicker animated:NO completion:nil];
}

#pragma mark - Camera Methods

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [self.tabBarController dismissViewControllerAnimated:NO completion:^{
        if(self.tabBarController!=nil)
            [self.tabBarController setSelectedIndex:0];
    }];
}

Any idea? 任何想法?

Simple idea: change this to: 简单的想法:将其更改为:

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self showPickerController];
}

Probably a better idea is to detect the source-type-available condition before beginning the transition to this vc, and instead present the picker vc instead. 一个更好的主意可能是在开始转换到该vc之前检测源类型可用的情况,而改为显示选择器vc。

In addition to danh's answer, add a BOOL property to your view controller and add a bit of code to your viewDidAppear: method: 除了danh的答案外,还向您的视图控制器添加BOOL属性,并向您的viewDidAppear:方法添加一些代码:

@property (nonatomic) BOOL appeared;

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    if (!self.appeared || [self isMovingToParentViewController] || [self isBeingPresented]) {
        self.appeared = YES;
        [self showPickerController];
    }
}

This will keep the UIImagePickerController from being immediately presented again after being dismissed. 这将防止UIImagePickerController被关闭后立即再次呈现。

Also, this isn't really relevant to the question, but you might want to change your showPickerController method a bit to prevent from showing an empty UIImagePickerController if there's no camera available: 另外,这与问题并没有真正的关系,但是您可能需要showPickerController更改showPickerController方法,以防止在没有可用摄像头的情况下显示空的UIImagePickerController

- (void)showPickerController
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.delegate = self;
        [self presentViewController:imagePicker animated:NO completion:nil];
    }
    else {
        UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Erreur !"
                                                          message:@"Votre iPhone n'a pas de Camera"
                                                         delegate:self
                                                cancelButtonTitle:@"Ok"
                                                otherButtonTitles:nil];
        [message show];
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:在演示文稿正在进行时尝试显示uiimagepickercontroller - Warning: Attempt to present uiimagepickercontroller while a presentation is in progress 错误:尝试呈现 - Error: Attempt to present <UIImagePickerController: on <ViewController: while a presentation is in progress 在演示过程中尝试呈现 UIViewController!-警告 - Attempt to present UIViewController while a presentation is in progress!-Warning Swift - 警告:在演示过程中尝试在 * 上演示 * - Swift - Warning: Attempt to present * on * while a presentation is in progress 警告:尝试呈现 - Warning: Attempt to present <UINavigationController while a presentation is in progress 是否可以忽略“警告:在演示过程中尝试演示……”是否安全? - Is it safe to ignore “Warning: Attempt to present … while presentation in progress”? 尝试呈现 - Attempt to present <DeviceDetailViewController…while presentation is in progress. any ideas? performSegue导致在演示过程中出现警告尝试 - performSegue causes Warning Attempt to present while a presentation is in progress iOS:警告:尝试出席 <ModalViewController> 上 <ViewController> 演示文稿正在进行中 - iOS: Warning: Attempt to present <ModalViewController> on <ViewController>while a presentation is in progress ios7-警告:在进行演示时尝试在UINavigationController上呈现UINavigationController - ios7 - Warning: Attempt to present UINavigationController on UINavigationController while a presentation is in progress
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM