UIModalPresentationFormSheet is not shown in iPad - iphone

I have a view controller which works perfectly in iPhone.
But when I present it in iPad with UIModalPresentationFormSheet style, it is blank. Nothing is inside it.
When I show it without setting Presentation style, it is shown perfectly. I use following codes:
[viewController setModalPresentationStyle:UIModalPresentationFormSheet];
viewController.view.superview.bounds = viewController.view.frame;
[self.navigationController presentViewController:viewController animated:YES completion:nil];
What would be problem and how can I solve it?

Related

Please assist with modalViewController crash

My app is crashing when I dismiss a ModalViewController via:
[self.parentViewController dismissModalViewControllerAnimated:YES];
This modal view-controller ("MVC") is presented when a user clicks on one of the cells of a UINavigationController ("NavRoot") - here's the code for that:
MVC *modalView = [[MVC alloc] initWithNibName:#"MVC" bundle:nil];
[self.navigationController presentModalViewController: modalView animated:YES];
[modalView release];
The "modalView" which is loaded contains only 2 objects: a UIWebView object and a "DONE" button, which when clicked-on does the dissmissing via:
[self.parentViewController dismissModalViewControllerAnimated:YES];
Except when I click on "DONE" - the app crashes.
When I run Instruments with NSZombies I do see the retain count reaches -1 but I can't tell what's causing this over-release.
The only thing I found which solves the problem is to either add a "[modalView retain]" statement in "NavRoot" - which is the viewController doing the presenting of modalView:
MVC *modalView = [[MVC alloc] initWithNibName:#"MVC" bundle:nil];
[self.navigationController presentModalViewController: modalView animated:YES];
[modalView retain]; // <<== new 'retain' statement
[modalView release];
or just simply never releasing modalView in the first place:
MVC *modalView = [[MVC alloc] initWithNibName:#"MVC" bundle:nil];
[self.navigationController presentModalViewController: modalView animated:YES];
// commenting out the 'release':
// [modalView release];
Both of these options throw flags when I run "Analyze" ("Potential leak of an object allocated on line 34"...) but they do fix the problem.
Still, I worry about this causing the app to be rejected by Apple from the App Store.
Any ideas on what may be causing the over-release? Or how I might further try to isolate / identify the problem?
attaching an image of Instruments/Zombies report:
Are u using iOS 5? I had the same problem when I switched an app from ios4 to 5.
ParentViewController is now called presentingViewController
What you can do though is in your modal view just call [self dismissModalViewController] and it should dismiss itself. I'm not 100% about that and can't check as I'm not near my mac, but I recall reading it in the docs,
If you do
[self.navigationController presentModalViewController: modalView animated:YES];
Then you should dismiss it like
[self.navigationController dismissModalViewControllerAnimated:YES];
Rather than
[self.parentViewController dismissModalViewControllerAnimated:YES];
Where are you trying to dismiss the view from? The actual modalView or the parentView? It seems to me that you are trying to dismiss a modal view that has already been dismissed and subsequently released.
To dismiss a modalViewController I simply just do: [self dismissModalViewControllerAnimated:YES];.
[self dismissModalViewControllerAnimated:YES] does not work on iOS 5.
I have built a category that add presentingViewController on iOS 4. (It disables itself on iOS 5.)
Just include 2 files, and it works seamlessly.
Please see backward-modal.
I hope this benefits you as much as it does to me; It makes your code more clean!

Customized UIImagePickerController issue when loaded a second time

I have made a UIImagePickerController with a custom overlay view in order to enhance the interface and it's working great the first time I load it, it's perfect.
The problem is that if I dismiss it and then shows it again I have a strange bug. the camera view and the overlay appear behind the NavBar and the TabBar of the previous view controller.
I have try different ways of implementing this but I can't get this bug solved.
Here is how I call my UIImagePickerController. It's inspired by this sample code.
[self.cameraOverlayViewController setupImagePicker:UIImagePickerControllerSourceTypeCamera];
[self presentModalViewController:self.cameraOverlayViewController.imagePickerController animated:YES];
Once my picture taken, I dismiss the UIImagePickerController:
[self dismissModalViewControllerAnimated:YES];
Definitly nothing special in the way of implementing it.
And here 2 screenshots:
And now taken at second launch:
At second launch http://puic.dev.madebykawet.com/IMG_0929.PNG
Thanks for your answers !
have you tried something like that?
//hide all controls
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;
picker.toolbarHidden = YES;
Thanks for your help Peko but it was not that.
After hours trying stuff, I found out that I needed to launch the UIImagePickerController from the root controller.
This is maybe because I'm using TTNavigator from the Three20 library.
So in my case to have this working:
[[TTNavigator navigator].rootViewController presentModalViewController:self.cameraOverlayViewController.imagePickerController animated:YES];
instead of:
[self presentModalViewController:self.cameraOverlayViewController.imagePickerController animated:YES];
same thing for dismissModalViewControllerAnimated:
[[TTNavigator navigator].rootViewController dismissModalViewControllerAnimated:YES];

ipad pushViewController display not as full screen

How to push an ViewController display not as full screen on iPad like the image below
Welcome any comment
Use UIViewController's modalPresentationStyle property, along with the standard presentModalViewController:animated:. Your screenshot is using UIModalPresentationFormSheet. There is also UIModalPresentationPageSheet, which displays fullscreen in portrait mode but leaves borders on either side in landscape.
The image you are showing is a type of modal view. You would display it with something like:
myViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[myViewController presentModalViewController: myModalViewController animated:YES];
See the documentation on UIViewController's for more info on modal views.
We can present the modalViewController in four different way .ie
1. UIModalPresentationFullScreen
2. UIModalPresentationPageSheet
3. UIModalPresentationFormSheet
4. UIModalPresentationCurrentContext.
Here you are using third One now..
if you dont want to use these thing simply use the following code..
[self presentModalViewController Animated:YES];
From the screenshot I take it that you're doing something like this:
UIViewController* newController = LoadTheController();
newController.modalPresentationStyle = UIModalPresentationFormSheet;
[currentViewController presentModalViewController:vc animated:YES];
But your question is referring to the "pushViewController" method, which is related to UINavigationController objects, and there is indeed a navigation controller in the background of the screenshot. You might try looking into something like this:
[currentViewController.navigationController pushViewController:vc animated:YES];

presentModalViewController problem - iphone sdk

I am using custom tabbar without the tabbar controller. When I try to add the viewController using
[self presentModalViewController:controller animated:YES];
edit: changed to presentsModalViewController.
which is for MFMailComposeViewController it works fine but it also removes the tabbar when I dismiss it.
For solution I had to present the controller on appDelegate.viewController like:
[APPDELEGATE.navigationController presentModalViewController:controller animated:YES];
edit: changed to presentsModalViewController.
This works fine and don't remove the tabbar. But the issue is when the iphone get locked after getting idle and I try to present the controller using this:
[APPDELEGATE.navigationController presentModalViewController:controller animated:YES];
edit: changed to presentsModalViewController.
It does not work.
In debug mode the code is executing but it is not presenting the viewController.
Many Thanks.
if you copied the Code right then you use
[APPDELEGATE.viewController dismissModalViewControllerAnimated:YES];
instead of
[APPDELEGATE.viewController presentsModalViewController:YOURVIEWController Animated:YES]; on the second call
I have fixed it myself. The problem was I was reallocating the navigation controller in the
- (void)applicationDidBecomeActive:(UIApplication *)application
Thanks.

Problem pushViewController from Landscape to Portrait

I am trying to go from a viewcontroller that supports landscape (while in landscape mode), to one that explicitly doesn't (and shouldn't) support landscape. I'm doing this as follows:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
Ideally I want the new viewController that i'm pushing onto the stack to start off initially in portrait, not landscape. Strangely even with this method implemented, it starts off in Landscape.
My only guess is that Apple doesn't want a user transitioning from landscape to portrait (despite allowing us to go from landscape, back to a previous controller that is in portrait).
Any insights and/or help would be much appreciated.
I found a way to force portrait. It's a bit a hack, but here it is. In the -(void)viewDidLoad of the viewController that you want to force portrait for do the following:
UIViewController *viewController = [[UIViewController alloc] init];
[self presentModalViewController:viewController animated:NO];
[self dismissModalViewControllerAnimated:NO];
[viewController release];
This basically forces portrait, by presenting a controller (which only supports portrait by default).
You will need to present your new view controller modally. If your view controller exists within a navigation controller the orientation of all view controllers in the nav stack is implied by the root view controller in the stack. Whatever your root view controller in the nav stack returns from shouldAutoRotateToInterfaceOrientation is then used for all view controllers below it.
The answer by Sahil above is deprecated since iOS 6.0. However, the following seems to do the same trick:
UIViewController *viewController = [[UIViewController alloc] init];
[self presentViewController:viewController animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
[viewController release];