dismissModalViewControllerAnimated crashes in ios 6.0 ipad simulator - ios

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.

Related

UIPopoverPresentationController is showing full screen modal on iPhone

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.

App not going to next view in iPad Simulator on iOS 6

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!

Presenting ModalViewController Modally on iPad

Im calling this code from the MasterViewController in a UISplitVC for an iPad app:
-(void)viewWillAppear:(BOOL)animated{
//PRESENT MODALVC
ModalViewController *modalVC = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
[self setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:modalVC animated:YES];
}
but it doesn't work. No ModalVC appears.
Try this code:
ModalViewController *modalVC = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
[modalVC setModalPresentationStyle:UIModalPresentationFullScreen]; //You set the presentation style of the controller that would be presented, not the presenting controller
//This check is needed, because presentModalViewController:animated is depreciated in iOS5.0 and presentViewController:animated:completion must be used instead. The same is valid for dismissModalViewControllerAnimated and dismissViewControllerAnimated:completion
if([self respondsToSelector:#selector(presentViewController:animated:completion:)])
[self presentViewController:modalVC animated:YES completion:nil];
else
[self presentModalViewController:modalVC animated:YES];
If you are targeting iOS5.0+ only this check is not needed and you should use only presentViewController:animated:completion and dismissViewControllerAnimated:completion

iOS 5.1.1 Popover not dismissing automatically

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.

Nothing works to remove UIViewController from screen

I have a modal view with a button and on click I add a fullscreen view controller. In ios 4.3 sdk it was dismissing when I asked to (and with push/pop controller methods and with present/dismiss modalViews) In new ios 5 sdk it fails to exit, parentViewController of my viewController is nil and I'm stucked.
Any suggestions?
Adding code:
myTypeController* vc = [[myTypeController alloc] initWithSomeData:myData];
vc.hidesBottomBarWhenPushed = YES
//This way
//[self.parentViewController presentModalViewController:vc animated:NO];
//Or that
[self.parentViewController.navigationController pushViewController:vc animated:YES];
[vc release];
And usual ways to remove it
[self.parentViewController dismissModalViewControllerAnimated:YES];
or
[self.navigationController popViewControllerAnimated:YES];
iOS 5 requires that you use presentingViewController:
if ([currentView parentViewController] != nil)
{
// iOS 4
self.isDismissingView = YES;
[[currentView parentViewController] dismissModalViewControllerAnimated:animated];
}
else if ([currentView presentingViewController] != nil)
{
// iOS5
self.isDismissingView = YES;
[[currentView presentingViewController] dismissModalViewControllerAnimated:animated];
}
More info here: http://omegadelta.net/2011/11/04/oh-my-god-they-killed-parentviewcontroller/
Use following code to close the modal view
[self dismissModalViewControllerAnimated:YES];

Resources