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.
Related
I know the SDK documentation says
Taps outside of the popover’s contents automatically dismiss the popover.
But I'm sure the smart people here found a way :)
maybe I should overwrite the popover dismiss function?
Thanks
EDIT:
I tried using the passthroughViews as was suggested here, and it works perfectly. Here's the code for whoever needs it - in this example, I put self.view in the array, which means that where ever outside the button where the popover was originated, nothing dismiss the popover.
popoverController.passthroughViews = [[[NSArray alloc] initWithObjects:self.view, nil] autorelease];
You need to set the passthroughViews property. From the documentation:
An array of views that the user can interact with while the popover is visible.
#property (nonatomic, copy) NSArray *passthroughViews
When a popover is active, interactions with other views are normally disabled until the popover is dismissed. Assigning an array of views to this property allows taps outside of the popover to be handled by the corresponding views.
Set passthroughViews to an array of view(s) that you want to handle the touch event instead of just dismissing the popover.
There is a very simple and legit solution. In the view controller that presents your UIPopoverController, conform to the UIPopoverControllerDelegate protocol and implement the following delegate method. I just tested this and it does prevent popover to dismiss.
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return NO;
}
Just make sure that you have set the delegate of your popover controller to the view controller that implements this.
You can dismiss the popover by using [popoverController dismissPopoverAnimated:NO]; method.
The accepted answer does not really answer the question, "is there a way NOT to have the popover dismissed when pressing outside it?", imo. It does give a possible view but could require hackish access to all parent views and determining what views are on the screen etc. The question could be rephrased as, "how do I make a popover view modal?"
You would do this like so, with a done button to close the popover:
UIViewController* vc = [[[UIViewController alloc] init] autorelease];
UIBarButtonItem* doneButton = [[[UIBarButtonItem alloc] initWithTitle:#"Done"] style:UIBarButtonItemStyleDone target:self action:#selector(processDoneAction)] autorelease];
[vc.navigationItem setLeftBarButtonItem:doneButton];
vc.modalInPopover = YES;
//If you want full screen:
vc.modalPresentationStyle = UIModalPresentationFullScreen;
vc.wantsFullScreenLayout = YES;
UINavigationController* navC = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
UIView* view = create your view
vc.view = view;
UIPopoverController* pc = [[[UIPopoverController alloc] initWithContentViewController:navC] autorelease];
pc.delegate = self;
self.popoverController = pc;
Then you'll in your processDoneAction method you will need to dismiss the popover. Other considerations would be dismissing and redisplaying on device orientation changes, but I will leave that to another exercise as that has been answered previously on stackoverflow.
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];
}
In my application the modal navigationcontroller that I am presenting is going under the current navigationcontroller so I'm not able to view the new navigationbar as it's disappearing under the current one.
I'm presenting the modalview on self and not self.navigationcontroller because self.navigationcontroller doesn't present the modalviewcontroller.
Also how to push a view on this modal navigationcontroller?
I'm using following code in one of my viewControllers:
fullListTopCompanies *fullListTopCompaniesInstance = [[fullListTopCompanies alloc] initWithNibName:#"fullListTopCompanies" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:fullListTopCompaniesInstance];
fullListTopCompaniesInstance.navigationController.navigationItem.title = #"F";
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[fullListTopCompaniesInstance release];
Can anybody please help?
Thanx in advance.
use animated with transition
according to me you have to change the animation style
i done it before but forgot the code i will post it when i get it
self.navigationController.navigationItem.title = #"F";
Add the above line of code in viewDidLoad method of "fullListTopCompanies" class.
Actually your navigation bar hides because of the modal view and modal view by default doesnt have Navigation bar.To add a navigation bar to modal view you can try the below code:
In Header File
IBOutlet fullListTopCompanies *fullListTopCompaniesInstance;
In Implementation File
UINavigationController *nav = [[UINavigationController alloc] initWithNibName:#"fullListTopCompanies" bundle:nil];
[self presentModalViewController:nav animated:YES];
[nav release];
Also on the "fullListTopCompanies" View Controller dont forget to put a left navigation bar button item for dismissing the modal view.
So add that left bar button (Ideally Cancel Button on navigation bar) and event handler for that left barr button should contain the code
[self dismissModalViewControllerAnimated:YES];
Hope this helps.
I have a subclass of TTMessageController that shows ... BUT it is not animated even though it should be. The code that displays the modal view looks like this (where PostToWebMessageController is the subclass of TTMessageController:
if (self.toWebMsgController == nil) {
self.toWebMsgController = [[PostToWebMessageController alloc] init];
}
UINavigationController *navController = [[UINavigationController alloc] init];
[navController pushViewController:self.toWebMsgController animated:NO];
[self presentModalViewController:navController animated:YES];
What happens though is this: The screen goes black ... the keyboard scrolls up into view ... and THEN the TTMessageController view shows up (not animated). When I dismiss the view via a Cancel button the screen goes black and then just disappears (no animation again).
Any ideas why this is happening? I've this with a number of other TT* controllers and I can't get one to animate right with showing modally.
Thanks
UPDATE:
This is happening in EVERY UIViewController that I try to present modally. Screen goes black, keyboard animates upwards and then view displays. Any ideas why this might be happening???
A day to figure this out ... hopefully someone will benefit from my pains!
Here is what is happening:
The UIViewController calling presentModalViewController is itself nested inside a UIScrollView that is contained in ANOTHER UIViewController. Apparently, cocoa touch doesn't much like this. Anyhow, to rectify the problem I did the following:
Add a property of type UIViewController to the UIViewController that will present a modal view controller (e.g. #property (nonatomic, retain) UIViewController *owningController;)
Set that property = to the topmost UIViewController (the one that contains the UIScrollView in this case)
In the UIViewController that shows the modal view ... change this
[self presentModalViewController:controller animated:YES];
to this ...
[owningController presentModalViewController:controller animated:YES];
I'm not sure why you are using a UINavigationController. If it is because you would like your toWebMsgController controller to have a nav bar when it loads in the modal view, try the following alterations to your code:
if (self.toWebMsgController == nil) {
self.toWebMsgController = [[PostToWebMessageController alloc] init];
}
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:toWebMsgController];
//[navController pushViewController:self.toWebMsgController animated:NO];
[self presentModalViewController:navController animated:YES];
If you don't require a nav bar in your modal view, you probably don't need a UINavigationController at all.
I had same issue.
Check that you root controller (if you present controller over it) for presentationStyle DOES NOT set to UIModalPresentationCurrentContext
I am using TabBarController in my application. In one of the view of the tabbar I am using a UIImagePickerController to pick an image.
When I add the picker as follows
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.editing = YES;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
It adds the picker, But at the time of choosing the photo, The bottom bar having the buttons "choose" and "cancel" gets hide under my tabbar. How to resolve this .
The problem is that you are using self as the navigation controller that shows the modal screen. Therefore the tab bar navigation controller does not know that a modal screen should fill the whole screen. Since the UIImagePickerController can not adjust itself to a smaller size you have to use the tab bar navigation controller to open present the modal view.
I use the following code to show a UIImagePickerController from a navigation controller that is shown inside a tabbar:
[self.navigationController presentModalViewController:picker animated:YES];
using self.navigationController instead of self as the object that presents the UIImagePickerController did the trick for me.
This works for me:
picker.delegate = currentClassViewController;
[tabBarController presentModalViewController:picker animated:YES];
Have your picker-caller class own or have access to your UITabController variable and presentModalViewController against your tabBarController.
I haven't seen this problem - I have an app that uses a UITabBar and a UIImagePickerController together, and the tab bar does not obscure the image picker.
Inside my view controller, which is one of the UITabBar's view controllers, I'm creating the image picker as such:
self.imagePicker = [[[UIImagePickerController alloc] init] autorelease];
imagePicker.allowsImageEditing = NO;
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
Seems very similar to your code, except that I'm setting the image picker as a retained property. Is your tab bar set up correctly? Is the view controller contained within the myTabBar.viewControllers array?