I have a class which has UIImagePickerController and extends UIViewController. But viewWillAppear/viewDidAppear are not being called for this class. Why so?
I want viewWillAppear to be there so that when I come back to this view, I can make some change.
By coming back you mean coming back from UIImagePickerController after selecting image/media?
If you want to display the image/media you selected from UIImagePickerController in your view,
you can make changes in the UIImagePickercontroller delegate method :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
which gets called as soon as you select any image or media from imagePicker. You just need to set the delegate of imagePicker to the the class in which you want to display the images.
Related
In my storyboard I have a NavViewController which sets the root view to ViewController1. ViewController1 then has a push segue to ViewController2 with the Identifier "socialSeg". ViewController1 has a UIImageView which I use to load the camcorder. After the user records the video and selects 'Use' i want to load the next view controller. In ViewController1.m I have the following:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(#"Performing Segue with ID");
[self performSegueWithIdentifier:#"socialSeg" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(#"Prepping");
}
Both NSLogs run, but nothing happens on my screen. I don't see the ViewController2, and no error messages pop up. Am I doing this correct?
Related question: Should I be running performSegueWithIdentifier on self (the current ViewController), or should they be ran on self.navigationController?
Edit: I tried to shorten my question somewhat to keep the post shorter, I realized you might need more context.
Here is my full storyboard. Basically "Video View Controller" would be ViewController1 and "Social View Controller" would be ViewController2. When I click on the "Root View Controller" button (Record Video), that segue works fine, which is why I left it out. Is there any chance the "Root View Controller" could be throwing things off?
There is nothing wrong with your performSegue code. It seems like your picker animation is still being run when you perform this Segue. Try calling performSegue in the completion block of presentViewController by modifying your present call as given below.
[imagePickerController presentViewController:YES completion:^() {
NSLog(#"Performing Segue with ID");
[self performSegueWithIdentifier:#"socialSeg" sender:self];
}];
Please make sure to replace imagePickerController with the name of your popup image picker controller.
Its not ideal solution but you can also delay execute your your performSegue to make sure your image picker animation has stopped as:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//1.5 is number of seconds its going to wait before executing the block of code
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.5 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
NSLog(#"Performing Segue with ID");
[self performSegueWithIdentifier:#"socialSeg" sender:self];
});
}
NOTE: The issue is that image picker popup animation is still in progress (to close the picker after user has picked an image or video) when performSegue tries to start another animation to load next view controller. Since one animation has not finished yet therefore performSegue animation gets ignored and view controller does not load.
Here is a related question and answer: performSegueWithIdentifier not working
I need your help please.
I have two different view controllers:
1. with a button
2. with an image view.
I'm trying to pass the button's image to the image view at the second view controller.
The prepareforsegue is being called but the image does not pass.
I attached my code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"pushGuessLogo"])
{
GeneralGuess *vc = [segue destinationViewController];
[self setLogoImageView:[[UIImageView alloc] initWithImage:self.logoImageSelected.imageView.image]];
[vc setImageGuessView:self.logoImageView];
}
}
ImageGuessView is the outlet of the image view at view controller number 2.
Thank you
Someone answered this the other day but I'm too lazy to find the link. (wouldn't it be great if SO also had a Knowledge Base which questions get promoted to, rather than endless questions that do not come up in a search).
The gist is that the viewController's view hierarchy is not yet set up at the point of prepareForSegue, so your ImageGuessView is nil at that point. What you can do is define a UIImage property on your GeneralGuess class and set that. Then in viewWillAppear load that image into your ImageGuessView.
The destination is not yet loaded when prepareForSegue is called so the image view is nil and thus nothing happens what you try to set the image.
Instead you should pass the image and store it in a property on the destination view controller and later set it in the image view in the destination view controllers viewDidLoad
I know this is a hot question for iPhone programming but I can't find a good answer yet.
I've an UITabBarController based application with the middle tabBarItem overlayed by a custom button. This custom button is used for posting a new item. Like this (I take Instagram, for example).
Of course this button must be accessible in the whole application.
When you click on this button you'll can see an UIImagePickerController for choosing an image from your library or from the camera.
The problem is how to display another UIViewController after you've chosen the image.
The first method is set a boolean variable from the UIImagePickerController delegate method and override the viewDidAppear method of all view controllers for checking the boolean var and if it's TRUE, call [self.tabBarController presentModalViewController:MyController animated:YES]. But I think this one is pretty ugly.
Have you others (elegant) method?
Create a new UIImagePickerControllerDelegate object, trap user actions, and either present a modal view controller or send a message to a view controller to handle it.
Let's say ViewController A is the class where you click on the camera button starting UIImagePickerController. ViewController Ashould be the delegate of UIImagePickerController.
Then, in ViewController A class, we define the function which is called when you click on the button Use.
// This function is invoked when you click the button USE
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Go back to the view A
[self dismissModalViewControllerAnimated:NO];
// Get Image
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Go to view B
[self.navigationController pushViewController:showMapViewController animated:NO];
I have a switched the cameracontrolls off, i mean
pickerCam.showsCameraControls=NO;
and i have custom capture button which does the capture functionality,
[pickerCam takePicture];
on click of this button the delegate will be called,
- (void)imagePickerController:(UIImagePickerController *)pi didFinishPickingMediaWithInfo:(NSDictionary *)info
Instead i need to implement custom 'Use' and 'Retake' option , how do i do that.
Thanks in advance
In imagePickerController:didFinishPickingMediaWithInfo: Method save the image captured in a global varialbe
Add a view to overlay having Use and Retake Button,
In the Use target dismiss the picker.
In retake target remove the view having Use and Retake buttons.
I'm working with tabBarBased application.At the time of clicking the one of the tabBarButton it opens the photo album .In photo album there is a cancel button on top(navBar) right??Here i want to perform action event for cancel button click...while click on the cancel button i want to go to the another tabBar view...
Please help me out to do this...
Thank You in advance for your consideration and effort...
Regards,
Renuga
Here's the class definition for UIImagePickerControllerDelegate:
#protocol UIImagePickerControllerDelegate<NSObject>
#optional
// The picker does not dismiss itself; the client dismisses it in these callbacks.
// The delegate will receive one or the other, but not both, depending whether the user
// confirms or cancels.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_2_0,__IPHONE_3_0);
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
#end
I think one of the methods mentioned above is what you need:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
set the selectedViewController property of UITabBarController to the view controller you want to switch to. Assigning a new view controller to this property changes the currently displayed view and also selects the appropriate tab in the tab bar.