Change modal UIImagePickerController parent view - iphone

I'm trying to build an app that features a button on the first view, when you tap the button it presents the UIImagePickerController modal view. What I would ideally like is once you have taken you photo, when the modal view is dismissed, the original view which presented the image picker changes.
For example, the process would be VIEW 1 -- (tap button) --> MODAL IMAGE PICKER -- (close modal view) --> VIEW 2.
So far I've got the app loading the UIImagePickerController and once you are complete, within the didFinishPickingMediaWithInfo delegate method, it sets a BOOL value to YES and then within the ViewDidAppear of my original view (VIEW 1) it then presents a new modal with the next view.
The problem with this is that there is a delay between the closing the modal view and the next view (VIEW 2) appearing.
Does anyone know if the above is possible? If not, I might have to resort to displaying a spinner and saying "Processing image" between the image picker closing and the second view appearing.

You can use a navigation controller to solve this problem.
Create a navigation controller and push your first controller into it. Later from your first controller, present the picker modally. Pretty much the same until now except that we have added a navigation controller. This is what I did to get your desired result.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NewController *controller = [[NewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
[self dismissModalViewControllerAnimated:YES];
[controller release];
}
Hope this helps.

Related

My map callouts don't display the image when clicked

I am developing an iPhone application for a university project and I'm new to iPhone development. I have looked through Apple's MapCallouts code but it doesn't seem feasible to implement it.
So far my code displays a map, drops annotations, displays the title and it displays the right call out button. But this is where I encounter problems.
When I press on the callout button, it displays a blank view controller but it should display a different image for every callout that's tapped and this isn't happening so far.
I have added my code below:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
//NSUInteger tag = ((UIButton *)control).tag;
if (self.detailController==nil)
{
DetailViewController* detailViewController = [[DetailViewController alloc] init];
[self.navigationController pushViewController:detailViewController animated:YES];
}
// self.detailController.tag =1; //to identify image required
// self.detailController.tag = tag;
[self.navigationController pushViewController:detailController animated:YES];
}
If you are using storyboard, then you should already have a view controller. I'm assuming your code is in the class that your view controller is an instance of.
The easiest (least coding required) way to present an image is to:
Drag a view controller into the storyboard
Drag a UIImageView into the view controller
Select the image you want to show up in the properties editor of the UIImageview
Control-drag from the button in your main view controller to the view controller containing the image
This should have created a segue. Select the segue and select "modal" from the style menu
You can do this for each image you want, but it is messy. Consider also subclassing the image controller and programmatically defining the image you want to show up. You may need to do this anyway if you want to dismiss the image with the dismiss modal view controller method. The alternative would be adding another segue that points backward.

dismissModalViewControllerAnimated also dismisses the view controller that calls it

I've got a view controller which is presented as a modal view controller on startup by the delegate. This view controller has an option to select an image using a UIImagePickerController which is presented using presentModalViewControllerAnimated. After this I implement the
imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
method and call dismissModalViewControllerAnimatedon it, but this dismisses both of the modal view controllers. I can't seem to keep the first view controller open when the second is closed.
Who are you calling dismissModalViewControllerAnimated on? You want to call it on the view controller that presented the modal view you want to dismiss.

Pushing a UIViewController from a modal view controller

I am using a split view controller in an iPad app I am trying to make.
Right now, I have a view being displayed in a modal view controller using:
[self presentModalViewController:viewController animated:YES];
and that works fine, but when the user presses a button, I want the root view controller to push to another view. I am using:
RootViewController *rvc = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
[rcv pushViewController:rvc animated:YES];
but that is not working. What should I do?
--EDIT
Now, I am using
PhotosViewController *pv = [[PhotosViewController alloc] initWithNibName:#"PhotosViewController" bundle:nil];
[self.parentViewController.navigationController pushViewController:pv animated:YES];
NSLog(#"Navigation Controller: %#", self.parentViewController.naviagtionController);
When I do the NSLog call, it returns nil. Why is that?
Once again, I am using a split view controller and am trying to push the RootViewController to a new view.
Thanks
Your code isn't working because you're created a RootViewController instance and then trying to push it onto itself. What you should be doing is pushing the new view controller onto the parent view controller's navigation controller:
[self.parentViewController.navigationController pushViewController:newViewController animated:YES];
I know this is an old question but I believe the proper way "now" to push a viewController onto the main navigation stack from a modal viewController is to create a "didTapShowBlahViewController" delegate on the modal (this is assuming you want the user to be finished with the existing modal view and then push a new view onto the stack). Once you have that delegate, you simply have the view that initially invoked the modal to perform dismissing the modal and pushing the next view controller when the delegate is triggered.
- (void)didTapShowBlahViewController{
[self dismissViewControllerAnimated:YES completion: nil];
[self performSegueWithIdentifier:#"segueToBlahViewController" sender:self];
}
This is based on Apple's View Controller Programming Guide that specifies passing data to child view controllers and using delegates to pass data back to parents.
FYI: This way also ensures that the "back" button will not go back to the modal but instead to the view that invoked the modal, which is how modals are typically used.

UIModalTransitionStylePartialCurl Flickers On Dismissal

I have a view controller with the following method:
- (IBAction)pickLocation:(id)sender{
SearchLocationPickerViewController *modalView = [[[SearchLocationPickerViewController alloc] init] autorelease];
[modalView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
modalView.searchVC = self;
[self presentModalViewController:modalView animated:YES];
}
This transitions perfectly fine, and displays the modal view controller as expected. However, when I dismiss the modal view using the following (executed from the modal view controller):
- (IBAction)closeLocationPick:(id)sender{
[self dismissModalViewControllerAnimated:YES];
}
The modal view transitions out as expected, but right at the end of the transition, the display will really quickly flicker SOMETIMES. It displays the modal view that was just displaying for a fraction of a second. This only happens maybe every three out of ten times of showing / hiding the modal view.
Any ideas on what could be causing this?
If I am reading your post correctly, one problem may be that you are dismissing the modal view from within itself. While this does work, it is not the way in which Apple prefers. I am making the inference that this may muck with the animation of the view as it is dismissed.
Your IBAction should be calling a delegate method in the modal view controllers parent, the one that created and presented the modal view controller originally. You define the delegate protocol in your modal view controller and adopt it in the view controller that makes the presentModalViewController: call.
Here are the relevant Apple docs on dismissing a model view.

modal view not showing inside didfinishpickingimage

I have a viewcontroller, and I would like to display a modal view controller with :
presentModalViewController when a user finished picking an image.
The modal view controller is working fine when I call it from a button in my main view.
But when I call it from didfinishpickingimage callback nothing happens.
Thanks.
Try
[picker dismissModalViewControllerAnimated:NO];
before
[self presentModalViewController:MY_VIEW_CONTROLLER animated:YES];
Note the animated variable
I had a similar issue. I decided to push the view controller I wanted to display after selecting an image onto my navigation controller instead of trying to present a modal view controller. It has the same effect as presenting a modal.
So I just did:
[self.navigationController pushViewController:MY_VIEW_CONTROLLER animated:YES];