My application works well on older OS' but on 5.1.1 (tested on both iPad2 and new iPad) popover shows up, runs well but does not dismiss when user taps outside the popover. I do not use any dismissal code or buttons. I used iOS 5.0 SDK, XCode 4.2 to compile the app. Here's how I show it up. Any ideas what could be wrong?
- (void)showNotifications {
NotificationsViewController *vc = [[[NotificationsViewController alloc] init] autorelease];
vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
if ([UIApplication isIPad]) {
vc.modalInPopover = YES;
self.popoverController = [[[UIPopoverController alloc] initWithContentViewController:vc] autorelease];
[self.popoverController presentPopoverFromRect:bottomView.frame inView:[bottomView superview] permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
else
[self presentModalViewController:vc animated:YES];
}
Mystery solved. Just commented out the line
//vc.modalInPopover = YES; must be no on iOS 5
ModalInPopover must be false on iOS 5. Don't know if it still works on iOS 4 though.
Related
On iPad UIPopoverPresentationController working fine but on iPhone it is always showing full window modal popup. i am using following code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MySecondViewController *contentVC = [storyboard instantiateViewControllerWithIdentifier:#"Pop"];
contentVC.modalPresentationStyle = UINavigationControllerOperationPop; // 13
UIPopoverPresentationController *popPC = contentVC.popoverPresentationController; // 14
contentVC.popoverPresentationController.sourceRect =CGRectMake(100, 130, 280, 230);
self.navigationController.preferredContentSize = CGSizeMake(200, self.parentViewController.childViewControllers.lastObject.preferredContentSize.height-100);
//self.showPop.frame; // 15
contentVC.popoverPresentationController.sourceView =
self.showPop; // 16
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny; // 17
popPC.delegate = self; //18
[self presentViewController:contentVC animated:YES completion:nil];
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}
In ViewController.h Firstly make a property of UIPopoverPresenatationController.
#property(nonatomic,retain)UIPopoverPresentationController *dateTimePopover8;
Then to show PopOverPresentationcontroller
UINavigationController *destNav = [[UINavigationController alloc] initWithRootViewController:dateVC];/*Here dateVC is controller you want to show in popover*/
dateVC.preferredContentSize = CGSizeMake(280,200);
destNav.modalPresentationStyle = UIModalPresentationPopover;
_dateTimePopover8 = destNav.popoverPresentationController;
_dateTimePopover8.delegate = self;
_dateTimePopover8.sourceView = self.view;
_dateTimePopover8.sourceRect = [sender frame];
destNav.modalPresentationStyle = UIModalPresentationPopover;
destNav.navigationBarHidden = YES;
[self presentViewController:destNav animated:YES completion:nil];
You must have noticed that we are presenting View Controller instead of presenting popOver.So we have to hide this in new way also.It hides automatically when we click on screen.
-(void)hideIOS8PopOver
{
[self dismissViewControllerAnimated:YES completion:nil];
}
We have to implement the delegate of UIPopoverPresenatationController in implementation file.Write below delegate method in implementation file.
- (UIModalPresentationStyle) adaptivePresentationStyleForPresentationController: (UIPresentationController * ) controller {
return UIModalPresentationNone;
}
Popover controllers are for use exclusively on iPad devices.
Edit: As stated by Soberman, since iOS 8 it is possible to present popovers on iPhone using public APIs, so this answer is probably not relevant anymore.
As stated in Apple's documentation on UIPopoverController:
Popover controllers are for use exclusively on iPad devices.
So there is no way to use this class in iPhone application unfortunately. But there are a couple of custom third-party implementations of the functionality provided by UIPopoverController which add iPhone support and more. See https://github.com/50pixels/FPPopover for example.
Edit: There also is another highly customizable popover implementation for both iPhone/iPad worth checking out: https://github.com/nicolaschengdev/WYPopoverController.
I have been searching for almost 2 hours on how to implement UIPopoverController in swift language, at the end, i found out that this api are exclusive for iPad devices only.
How will i be able to make a drop down list on iPhone devices?
please someone help me, at lease with the name of the api so that i know what to search for
You can you third party libraries for that:
FPPopover
WEPopover
or if you don't need iOS 7 support you can use iOS 8 new API which answered in this question
UIPopoverPresentationController on iOS 8 iPhone
i depends on your needs. You can show UIPickerView, present an action sheet or segue to another VC and then go back - these are standard ways.
#property(nonatomic,retain) UIPopoverPresentationController *popoverPresentationController;
- (IBAction)showPopover:(id)sender {
UIViewController *popoverViewController = [[UIViewController alloc] initWithNibName:#"NameViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:popoverViewController];
popoverViewController.preferredContentSize = CGSizeMake(280, 200);
navigationController.modalPresentationStyle = UIModalPresentationPopover;
_popoverPresentationController = navigationController.popoverPresentationController;
_popoverPresentationController.delegate = self;
_popoverPresentationController.sourceView = self.view;
_popoverPresentationController.sourceRect = [sender frame];
navigationController.modalPresentationStyle = UIModalPresentationPopover;
navigationController.navigationBarHidden = YES;
[_viewController presentViewController:navigationController animated:YES completion:nil];
}
The scenario is like this:
lets say ViewControllers A, B.
A supports only portrait mode. B supports all modes.
I tap on thumbnail image from A and showing full image in B. So auto-rotation works fine in B. It works fine, If I come back to A from B when B is in portrait mode.
But the problem is if I keep my phone in landscape mode when I was in B then if I come back to A then it is also showing landscape which is not supposed to happen.
I was working totally fine in iOS7 but it is messing up in iOS 8.
Can anyone help with this? Thanks in advance.
Something is wrong with your code. I just implemented it to test and it works fine.
I addded to A:
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Added to B:
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
and added the button to A to open B:
- (IBAction) buttonAction:(id)sender
{
UIStoryboard *story = [UIStoryboard storyboardWithName:#"itShouldWork" bundle:nil];
MyViewController *controller = (MyViewController *)[story instantiateInitialViewController];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller];
[self presentViewController:nav animated:YES completion:nil];
}
As I said, it works fine. tested on iphone 5 device (iOS 8). Built with Xcode 6
It appears to be a bug in iOS 8.
As a workaround you can wrap your B controller in UINavigationController. Along with checking for iOS version it would look like
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8")) {
[self presentViewController:[[UINavigationController alloc] initWithRootViewController:controllerB] animated:YES completion:nil];
} else {
[self presentViewController:controllerB animated:YES completion:nil];
}
Macros for checking iOS version can be found here.
I am using the following code to dismiss modal view controllers:
- (IBAction)done {
#ifdef __IPHONE_5_0
if ([self respondsToSelector:#selector(presentingViewController)])
[self.presentingViewController dismissModalViewControllerAnimated:YES];
else
#endif
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
If I runt he simulator using iOS 4.3 iPad, it uses self.parentViewController and works fine. However, when I runt he simulator using iOS 6.0 iPad the simulator crashes right after the view is dismissed using self.presentingViewController.
I do not have an actual iPad to test on... any ideas?
EDIT:
below is the code that creates the modal view controller.
NSArray* errors = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Errors" ofType:#"plist"]];
UIViewController* vc;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
DocumentsViewController_iPad* docsVC = [[DocumentsViewController_iPad alloc] initWithNibName:#"DocumentsViewController-iPad" bundle:nil];
docsVC.documents = errors;
docsVC.errors = YES;
docsVC.navTitle = #"Troubleshooting";
vc = docsVC;
} else {
DocumentsViewController* docsVC = [[DocumentsViewController alloc] initWithNibName:nil bundle:nil];
docsVC.documents = errors;
docsVC.errors = YES;
docsVC.navTitle = #"Troubleshooting";
vc = docsVC;
}
vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:vc animated:YES];
[vc release];
A few things:
Yes, you should use dismissViewControllerAnimated:completion: as #rdelmar said
You should call it on presentingViewController, not parent
You can skip going to the presenting controller and dismiss self, it will forward this message to the presenting controller if needed.
dismissModalViewControllerAnimated: is depreciated, use dismissViewControllerAnimated:completion: instead.
I have an older iOS app that has 2 views, a MainViewController and a FlipsideViewController. For some reason, when I press a button that switches from the MainViewController to the FlipsideViewController, the app just freezes, and the log shows no crash. This only happens on the iPad simulator with iOS 6. The app works fine on the iPhone simulator with iOS 6.
Here's the code I'm using in my MainViewController to switch to the other:
FlipsideViewController *controller;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView-iPad" bundle:nil];
} else {
controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
}
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
[controller release];
If I put an NSLog() statement in the top of the viewDidLoad of FlipsideViewController, it does output to the debug log. But the view is never shown.
It should also be noted that the FlipsideViewController does contain MPMusicPlayerController code, but this line has been commented out since it usually causes issues on the simulator:
self.musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
Any ideas? Thanks!