Reputation: 167
I am trying to load picture chooser in iOS it works fine in the first attempt but when i do this for the second time it gives me the following warning
Warning: Attempt to present on whose view is not in the window hierarchy!
my code for picking image is as follow
[self startCameraControllerFromViewController:self usingDelegate:self sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
and the method is as follows startCameraControllerFromViewController
- (BOOL) startCameraControllerFromViewController: (UIView*) controller usingDelegate: (id) delegate sourceType:(UIImagePickerControllerSourceType) sourceType{
if (([UIImagePickerController isSourceTypeAvailable:
sourceType] == NO)
|| (delegate == nil)
|| (controller == nil))
{
DLog(@"no is being returned");
return NO;
}
if(_delegate != nil &&[ _delegate respondsToSelector:@selector(imagePickerOpened)]){
[_delegate imagePickerOpened];
}
if(cameraUI==nil){
// [SVProgressHUD showWithStatus:@"Loading"];
[ALERT showLoader];
dispatch_queue_t concurrentQueue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^{
cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = sourceType;
cameraUI.mediaTypes=cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
cameraUI.allowsEditing = YES;
cameraUI.delegate = delegate;
dispatch_async(dispatch_get_main_queue(), ^{
[self.window.rootViewController presentModalViewController:cameraUI animated:YES];
//[self presentModalViewController:cameraUI animated:YES ];
[ALERT hideLoader];
});
});
}
else{
cameraUI.sourceType = sourceType;
[self.window.rootViewController presentModalViewController:cameraUI animated:YES];
//[self presentModalViewController:cameraUI animated:YES ];
}
return YES;
}
Upvotes: 1
Views: 4439
Reputation: 167
The issue was related setting root view controller i had set a root view controller that was not present so i set my current view controller to be root view controller and it fixed my issue.
Upvotes: 1