I want to present a modalViewController(do some picture drawing) right after dismiss the imagePickerController(exactly after finish image picking). I've tried to set up a IBAction with a bar button and it works fine when I tap it. But what I want is present the modalViewController as soon as I finish the image picking
Here is my code:
-(void)imagePickerController:(UIImagePicerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info{
[self dismissModalViewControllerAnimated:YES];
//dismiss the imagePickerController
drawViewController *drawView = [[drawViewController alloc] init];
[self presentModalViewController:drawView animated:YES];
}
Thanks!
The dismiss and presentModal can't both animate in the same method. The presentModal will seem to do nothing. For the dismiss, try setting the animated to NO.
After dissmissing the imagePickerController the viewDidAppear is called. You can there call the drawViewcontroller.
-(void)viewDidAppear:(BOOL)animated{
drawViewController *drawView = [[drawViewController alloc] init];
[self presentModalViewController:drawView animated:YES];
}
Related
I am loading a ABPeoplePickerNavigationController on the click of a UITableViewCell.
self.peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
self.peoplePicker.peoplePickerDelegate = self;
[self.peoplePicker setDelegate:self];
self.peoplePicker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:self.peoplePicker animated:YES completion:nil];
When the picker is presented as UIModalPresentationFormSheet, I want to disable the UIViewController behind it. For that I could load a transparent view on presenting the picker and dismiss it when the picker is dismissed. So the tap on the viewcontroller wont work.
I would like to know if there is another way to do it, where I wouldn't require to create a new UIView and load/dismiss it.
You can setUserInteractionEnabled property on the view of the ViewController before presenting and after dismissing the Picker view.
I have a problem with the function call:
[self dismissModalViewControllerAnimated:YES];
In MainViewController, I can launch a image picker and dismiss as usual by clicking the cancel button.
(IBAction) LaunchInMain:(id)sender{
MainAppDelegate *app = (MainAppDelegate *)[[UIApplication sharedApplication] delegate];
//elcPicker is a customized image picker
[app.viewController presentModalViewController:elcPicker animated:YES];
[elcPicker release];
[albumController release];
- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker {
[self dismissModalViewControllerAnimated:YES];
}
Now, instead of launching it direct it in Main, I add a subview first and launch the image picker from the subview using the same launch method.
Problem:
The image picker cannot be dismissed and the subview cannot be shown again. So the screen will remain at the image picker no matter what I click.
I have been trying with some other calls like without any success:
[self dismissModalViewControllerAnimated:YES];
I am happy with any help or idea. If you think more information should be provided, I can add more codes.
May be try
[app.viewController dismissModalViewControllerAnimated:YES];
Hope this helps.
This may work for you:
[self.view dismissModalViewControllerAnimated:YES];
This works if you are presenting a modal view from a UISplitViewController. It can also be applied in so many other ways...
First, create an instance in your .h file for your appDelegate, (AppDelegate_iPad *appDelegate) then put this in your viewDidLoad or comparable method:
ipadDelegate = (AppDelegate_iPad *)[[UIApplication sharedApplication] delegate];
Now, present the first modal view like this:
YOURVC *vc = [[YOURVC alloc] initWithNibName:#"YOURVC" bundle:nil];
[ipadDelegate.splitViewController presentModalViewController:vc animated:YES];
[vc release];
Say you have a subview, like a UITableView, and want to dismiss the modal from the didSelectRowAtIndexPath. All you have to do to dismiss your modal with a subview is create another ipadDelegate instance inside your subview's .h (if needed), reference the [[UIApplication sharedApplication] delegate] again, and dismiss:
[ipadAppDelegate.splitViewController dismissModalViewControllerAnimated:YES];
Essentially, as long-winded as it may be, use your appDelegate's controller to present and dismiss the the modal if you need to maintain a persistent reference to the presentingViewController...because all the things above just don't work in my case.
If you're presenting with your ipadDelegate, make sure you check the mode of presentation in your MainWindow_iPad.xib. Your "Transition Style" should be "Cover Vertical" and "Presentation" should be "Current Context" or your modal may present behind other views.
on iOS 4 i am using the following line of code to get the PhotoLibrary and its working perfect and the view can be dismissed with the cancel button appearing on top right side:
[self presentModalViewController:imgPicker animated:YES];
However, on iOS 5 the following line is getting the PhotoLibrary but the "Cancel Button" is Disable, i.e. the view cannot be dismissed with cancel button.
[self presentViewController:imgPicker animated:YES completion:nil];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
[self presentModalViewController:imagePicker animated:TRUE];
This works fine for me, in iOS 5, too.
You are not passing a view controller, but a view controller class. Try using your old imgPicker rather than the UIImagePickerController.
Also, there is no such thing as Nil in objective C. It should be nil.
From the rootViewController I navigate to a UIViewController
if (self.contr == nil) {
ExampleViewController *controller = [[ExampleViewController alloc]
initWithNibName:#"Example"
bundle:[NSBundle mainBundle]];
self.contr = controller;
[controller release];
}
[self.navigationController presentModalViewController:self.contr animated:YES];
In the UIViewController I have the method
-(IBAction) goBack:(id)sender {
[self.navigationController dismissModalViewControllerAnimated:YES];
}
I added the signature to the .h file.
In the .xib file, I have a UIToolbar with a UIBarButtonItem. I connected the button to the File's Owner - goBack:
Everything appears in the screen, but when I click on the button, goBack isn't called. I also tried to do this programatically instead, but I got the same result - everything appears, but no reaction to the click.
Any ideas why it isn't working?
Edit:
I just found out something invisible is over the toolbar. If I click on a specific point (over the toolbar), then goBack: is called. Since I navigated to this screen using presentModelViewController, the navigation bar isn't appearing... but probably it's there and that's what is hiding the tool bar.
Have bind your Toolbar with File Owner?
As your UIBarButton is subview of UIToolbar so you have to bind Toolbar with File Owner.
Presenting a modal view controller do not require you to pass through a UINavigationController. I suggest you to change this:
[self.navigationController presentModalViewController:self.contr animated:YES];
[self.navigationController dismissModalViewControllerAnimated:YES];
to this:
[self presentModalViewController:self.contr animated:YES];
[self dismissModalViewControllerAnimated:YES];
Let me know if this helps.
Try this in the goBack method :
[self.navigationController popToRootViewControllerAnimated:YES];
If you are not hitting the breakpoint that means you did not connect them properly in the xib.
As shown in the screenshot below, i have a UITableView with some info and upon selecting a row an ABUnknownPersonViewController is invoked. In order to be able to able to dismiss that and go back to the UITableView I have this code:
ABUnknownPersonViewController *unknownPersonView = [[[ABUnknownPersonViewController alloc] init] autorelease];
[unknownPersonView setUnknownPersonViewDelegate:self];
[unknownPersonView setDisplayedPerson:personRecord];
[unknownPersonView setAllowsAddingToAddressBook:YES];
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:#"Επιστροφή" style:UIBarButtonItemStylePlain
target:self action:#selector(goBackToView)];
unknownPersonView.navigationItem.title = #"Προσθήκη στις επαφές";
unknownPersonView.navigationItem.leftBarButtonItem = anotherButton;
navigationController = [[[UINavigationController alloc] initWithRootViewController:unknownPersonView] autorelease];
//navigationController = [[[UINavigationController alloc] initWithRootViewController:self] autorelease];
//self.navigationItem.rightBarButtonItem = anotherButton;
[self presentModalViewController:navigationController animated:YES];
} // didSelectRowAtIndexPath ends here
- (IBAction)goBackToView {
[self dismissModalViewControllerAnimated:YES];
}
- (void)unknownPersonViewController:(ABUnknownPersonViewController *)unknownPersonView didResolveToPerson:(ABRecordRef)person {
// CallerIDAppDelegate *delegate = (CallerIDAppDelegate *)[[UIApplication sharedApplication] delegate];
[navigationController dismissModalViewControllerAnimated:YES];
}
The problem (as you can see) is that when the ABUnknownPersonViewController is dismissed by the "Επιστροφή" button, which is "Back" actually, the view holding the tableView and the blue UIButton is moved a couple of pixels to the bottom!
Any help on what could be causing this?
Screenshot http://dl.getdropbox.com/u/1237004/problem.jpg
Debug this by checking your view's frame in -viewWillAppear, -viewDidAppear, -viewWillDisappear, and -viewDidDisappear.
Also check the view's autoresizingMask, and the parent view's autoresizesSubviews property.
I'm not sure I see the value of setting up a navigation controller here. You could just present the ABUnknownPersonViewController with [self presentModalViewController: unknownPersonView];. If you're doing it for the sake of picking up the visual navigation bar with the back button, then just add a nav bar and button to the unknown person view.
It seems like a mixed metaphor to be creating a UINavigationController but then not using its usual navigation methods (e.g., pushViewController:animated: and popViewControllerAnimated:) and instead using the modal methods inherited from UIViewController.
It seems that adding this line:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
in my viewWillAppear: made the view not to move when the modal view controller is dismissed. However now the initial position was already slightly dislocated to the bottom but fixed it by moving all the outles in IB to the top so it looks ok.