While trying to present the contact editor VC I get an error message of
Warning: Attempt to present <UINavigationController: 0x15fe273f0> on <UINavigationController: 0x15fe0e730> while a presentation is in progress!
I believe this is because my UIImagePickerController is still active.
Here is my didFinish method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = info[UIImagePickerControllerOriginalImage];
animated:YES];
[picker dismissViewControllerAnimated:YES completion:NULL];
[self scanWithImage:image];
}
As you can see the second message should dismiss the VC but it does not, and it stays up until the end of the execution of the application.
scanWithImage: eventually calls showNewPersonViewController here is that method:
-(void)showNewPersonViewController
{
ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];
picker.displayedPerson = _person;
picker.newPersonViewDelegate = self;
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:picker];
// Change status bar back to black due to white contact creation.
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
[self presentViewController:navigation animated:YES completion:nil];
}
On the last line in that method I get the error message, then the app finishes its execution and returns to the main VC.
How can I avoid this and properly display the contact creation VC?
Let's try:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = info[UIImagePickerControllerOriginalImage];
// I think picker should change to self == this class dismisses, not picker dismisses
[self dismissViewControllerAnimated:YES completion:nil];
}
// should implement [self scanWithImage:image]; in parent class which contains VC has pickerView.
// Because after dismissing, VC which contains picker is dealloc, how can you call [self presentViewController:navigation animated:YES completion:nil];
I think this can help you
I think you are presenting two VCs at same time with animation.
Set one of VC's animation to NO while presenting or dismissing and see if the warning goes away.
I'm not 100% sure but if you want both animations you should run the second one on the first one's completion block or use a timer to delay the second view controller's navigation start.
Related
I have a viewController VC1 where I present an UIImagePickerController with sourcetype camera.. then after taking a picture, transition to a new viewController where the image is used. The problem is, how can I dismiss the imagePicker AND seamlessly transition to my new viewController. For example in my
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
method, I attempt to use either of the two methods to dismiss the picker and present the new viewController seamlessly
[self.presentedViewController presentViewController:postControl animated:NO completion:^{
[picker dismissViewControllerAnimated:NO completion:nil];
}];
/*
[picker dismissViewControllerAnimated:NO completion:^{
[self presentViewController:postControl animated:NO completion:nil];
}];
*/
Obviously the first one is wrong because I am asking the presenting view controller to dismiss itself during its animation, resulting in an error. If I change picker to self.presentingViewController it never dismisses the camera and the second bit of code(the one commented) works, but not seamlessly, In other words, You can SEE the transition.
Sorry for not understanding this problem but I am just not seeing it. How can I dismiss the camera AFTER or BEFORE presenting postControl seamlessly?
As in, you cannot see the transition?
UIViewController* toPresentViewController = [[UIViewController alloc] init];
[picker dismissViewControllerAnimated:YES completion:^
{
[self.presentingViewController presentViewController:toPresentViewController animated:YES completion:nil]
}];
I have everything i want working up to the view you can see in the picture, i don't want the image to load on the same screen, how can i get it to load in a new screen. i have tried a few tutorials, i have had no luck as yet
The image that has been loaded from the gallery is the brick wall in the background.
the reason i want to load it in a new screen is so i can put a new toolbar that will allow me to drag images and overlay them on top of the image selected from taller or taken with the camera
Thanks in advance and sorry for asking about something that sounds so simple, I'm just very new to all this.
http://imageshack.com/a/img845/4808/9lz8.png
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
How do i open new screen when didFinishPickingMediaWithInfo
If you need to see me more code please let me know which, I'm not sure what code you need to see :) thank you for your reply.
If you want the image to load on a new screen, you'll need to create a second viewController, and add an imageView to that viewController.
then in your didFinishPicking method, instead of setting the image to the imageView of the current ViewController, instantiate a new imageController, set the imageView property of the new viewController, and then push your new viewController onto the navigation stack if you're using a navigation controller. If you're not using a navigation controller, you could just push the second view controller modally.
So in your didFinishPicking method it would be
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
NewViewController *newViewController = [[NewViewController alloc] init];
newViewController.imageView.image = chosenImage; //or whatever the imageView property is called of your new view controller
[self presentViewController:newViewController animated:YES completion:nil];
(I haven't tested this code - it's off the top of my head so reader caution advised and this is the modal method)
Let's try:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:^{
// I think you should not call `presentViewController` newViewController at this screen because it maybe be destroyed
// So, call newViewController at parentClass by delegate of block
// and assign new image to the screen which need to show
}];
}
This worked in iOS6, so not sure what the issue is.
inside my UINavigationController (ioNavController) I present the UIImagePickerController with the Following:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.modalInPopover = YES;
imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:imagePicker animated:NO completion:^{ }];
in my UIImagePickerControllerDelegate (which does get called)I have the Following:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
//This does not work
[ioNavController dismissViewControllerAnimated:YES completion:^{ /* Cleanup if Needed */ }];
//This does not work
[[picker parentViewController] dismissViewControllerAnimated:YES completion:^{ /* Cleanup if Needed */ }];
//This does not work
[picker removeFromParentViewController];
// This presents a new view on the Nav Controller. It shows the new view ontop of the ImagePicker. Image Picker View does not repond to touches.
[ioNavController pageToSelect:0];
}
Your delegate it's in the same controller that called the imagepicker? The same controller that called presentViewController should call the line below, and the imagepicker will be removed correctly.
[self dismissViewControllerAnimated:YES completion:nil]; //self here it's the same reference that called presentViewController
let me know if worked or helped.
The UIImagePickerController will remove itself when you use this code:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)pPicker {
[pPicker dismissViewControllerAnimated:YES completition:NULL]; }
I am learning how to handle view controller hierarchies using the storyboard. I have 2 ViewControllers: the root of type cwViewController (what I understand is 'self' below) and a second of type WorkspaceViewController. I am getting "Attempt to present while a presentation is in progress!" as a result of this code.
- (IBAction)nextView {
WorkspaceViewController *workspace = [[WorkspaceViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:workspace animated:YES completion:NULL]; }
The answer to How to present view controller properly? is the closest answer that could apply but doesn't quite fit this scenario because I'm not switching back and forth between VCs, I'm just presenting one, then dismissing it to display the original.
Then, I tried dismissing the current one before presenting the second, as some answers suggested, like this:
[self dismissViewControllerAnimated:NO completion:nil];
[self presentViewController:workspace animated:YES completion:NULL];
But that just gets me an additional Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!
Doing some other research I saw similar problems were solved by adding a block to
[self dismissViewControllerAnimated:YES...]
But that doesn't help here because my warning occurs before I even get to a point where I call that dismiss method. Any further knowledge on how the order and hierarchy of views are meant to be handled would be a big help. Thanks very much.
Did you create a segue from the button to your WorkSpaceViewController? If so, you are likely attempting to present the WorkSpaceView twice - once when the button is selected and once from cwViewController. To eliminate the error, delete the segue from the button to WorkSpaceViewController and then recreate the segue - this time between cwViewController and the WorkSpaceViewController. That should take care of it.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// TODO: make this all threaded?
// crop the image to the bounds provided
img = [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(#"orig image size: %#", [[NSValue valueWithCGSize:img.size] description]);
// save the image, only if it's a newly taken image:
if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
}
// self.image_View.image = img;
// self.image_View.contentMode = UIViewContentModeScaleAspectFit;
NSLog(#"Picker has returned");
[self dismissViewControllerAnimated:YES
completion:^{
ModalViewController *sampleView = [[ModalViewController alloc] init];
[self presentModalViewController:sampleView animated:YES];
}];
}
try
[self presentModalViewController:workspace animated:YES];
if (![[self modalViewController] isBeingPresented]) {
[self dismissModalViewControllerAnimated:YES];
}
I'm trying to make an iOS application with 2 views. First view contain two buttons: Camera and Library. When i select Library i access the camera roll. I wanna select a photo and open it in another view. Until now i write this functions
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentViewController:picker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion: Nil];
imageView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
witch open my image in the same view. How could I open this image in another view?
You can do something like that
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
[picker dismissViewControllerAnimated:YES completion:^{
YourSeconViewController *svc = [[UIViewController alloc] initWithNibName:#"YourSeconViewController" bundle:nil];
svc.imageView.Image = image;
[self presentViewController:svc animated:YES completion:nil];
}];
}
The steps I suggest are:
Make sure that you declared a view controller subclass, preferably with a xib file and make sure that it has an image view inside it;
If you aren't using any navigation controller, create one and make it be the root view controller of the window;
Push a view controller and set it's image view's image with the image that you want to set.
Displaying the image in another view in the same view controller is trivially simple - assuming you have a reference to the new view in your viewController, just use that:
NewImageView.image = ...
I assume that you rather mean you want to pass the image to another view controller.
To do this you should initiate the transition to the new viewController from your imagePickerController:didFinishPickingMediaWithInfo: method.
In your new view controller you should declare a public property that you can set:
#property (monatomic, strong) UIImage* Image;
You can set that property on the new view controller before you transition to it, and in the new view controller's viewWillAppear use that property to set the content of an imageView.
How you make the transition depends on the design of your app. For example you could use a Segue, in which case you can initiate the segue in didFinishPickingMediaWithInfo: and set the new view controller's property in prepareForSegue. Or you could create the new VC directly:
MyCustomViewController* viewController = [[MyCustomViewController alloc] init];
//pass the image ref to the new view controller here
ViewController.image = image;
//modally present, no navController
[self presentViewController:viewController animated:YES];
//alternatively, push via a nav controller
[self.navigationController pushViewController:viewController animated:YES];