[英]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.