Display a view using modalPresentationStyle - cocoa-touch

I have heard that you can make a view popup like in the Mail app for iPad by using modalPresentationStyle. Im having a hard time figuring out how to use it though. I looked a this post here and still couldn't figure out how to do this task. If anyone could explain how to hook up the controllers to make this code work that would be great.
Thanks

I think the magic incantation is the following:
myViewController = ..... create your new controller if needed ....
myViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
myViewController.modalPresentationStyle = UIModalPresentationFormSheet;
// "self" here is a ViewController instance
[self presentModalViewController:myViewController animated:YES]
I seem to recall that in portrait the modal takes over the screen; in landscape it will be presented centered in the view.

Related

presentModalViewController gives a black screen

In an alert view method I implemented the following (pretty standard) piece of code for popping a modal view:
else if (buttonIndex == 1) {
EmergencyPlanViewController *emergencyPlanView = [[[EmergencyPlanViewController alloc] init] autorelease];
[emergencyPlanView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:emergencyPlanView animated:YES];
}
Somehow it gives me a black screen as result. I can't find what is wrong here.
I created the window in my MainStoryBoard and customized the class of the viewcontroller in IB to EmergencyPlanViewController.
The viewDidLoad method of the emergencyPlanView is triggered but it looks like the view is not loaded. Anyone an idea what's wrong here?
EDIT:
To be clear, I am not using seperate xib-files in my project. I only use the storyboard
In the xib file, is your UIView set to the File Owner's view. That is probably the problem. Also if you just apply init, that will load the EmergencyPlanViewControllerinterface builder file with the same name:
EmergencyPlanViewController.xib
So make sure in that case that either:
The EmergencyPlanViewController nib is indeed: EmergencyPlanViewController.xib
or that you write instead of init: initWithNibName://whatever nib name here
I managed to fix the black screen issue when presenting a modal view controller by setting a background color to the view in Interface Builder. I noticed that by default the background color of the view is set to something like black/white (see picture attached), although it appears in white. I don't know exactly what does this mean or how it is responsible for showing a black screen, but setting a single color or texture fixed it. PS: I've faced this when migrating from iOS SDK 5 to 6.
ios6
Try this:-
EmergencyPlanViewController *emergencyPlanView=[[EmergencyPlanViewController alloc] initWithNibName:#"EmergencyPlanViewController" bundle:nil];
emergencyPlanView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:emergencyPlanView animated:YES];

Reloading a view

I can't find the correct method on how to reload a modal view controller from within itself. I'm developing a very simple UI based app but I'm not sure how to do this.
I open the modal view with the following:
MainView *mainmview = [[MainView alloc] initWithNibName:#"submod" bundle:nil];
mainmview.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self mainmview animated:YES];
and then can dismiss it depending on iOS version. However this has no effect when used on what i need to be a simple restart button. Any help is appreciated.
You will have to implement your own "refresh" functionality - define a "refresh" method inside the modal view controller's class and do whatever needs to be done inside it - if for instance you have a tableview that requires a reload or to refresh your views depending on new data, etc...

PresentModalViewController from within UISplitViewController: weird behavior in landscape mode

I've been using PresentModalViewController a lot and never had any issues. But when showing a modal controller from within any controller hosted by a UISplitViewController I get strange orientation bugs.
In my table view (which is root controller of the UISplitView), when a cell is touched, I call:
MyController oModal = new MyController();
oModal.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
oModal.ModalTransitionStyle = UIModalTransitionStyle.CrossDissolve;
this.PresentModalViewControll(oModal, true);
If the iPad is in Portrait, all is okay. If it is in landscape however, the modal controller fades in but its orientation is incorrect. Then, after fading in has finished, it suddenly flips 90 degrees and adjusts to correct orientation.
I have overriden ShouldAutoRotateToInterfaceOrientation(), so that cannot be it.
Ideas?
René
I bumped into this and have a workaround, not a real solution. The problem is that the UIViewController you are presenting your modal controller from (in you code "this") is responding with the incorrect orientation to it's property interfaceOrientation. It happened to me and I'm not really sure why. The workaround is to add a custom getter for the property in your UIViewController ("this") like the following:
-(UIDeviceOrientation)interfaceOrientation
{
return [[UIDevice currentDevice] orientation];
}
I got the idea from this post. I believe the problem is that the View Controller is not properly embedded into the view controller hierarchy but haven't figured out how. Hope this helps.

positioning problem with uisplitviewcontroller in left view

i got a little problem, when launching my splitview in landscape, there is a little black space above my left view controller:
after rotating my ipad to portrait and switching back to landscape, the space is gone.
if i load the uitableviewcontroller directly into the left view, and not in a navigationcontroller, it works fine:
any ideas why this is happening ??
// Produkte
self.produkteMainTableVC = [[produkteMainTableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *produkteMainNavigationController = [[UINavigationController alloc] initWithRootViewController:self.produkteMainTableVC];
self.produkteDetailVC = [[produkteDetailViewController alloc] initWithNibName:#"produkteDetailViewController" bundle:nil];
self.produkteSplitVC = [[UISplitViewController alloc] init];
self.produkteSplitVC.delegate = self.produkteDetailVC;
self.produkteMainTableVC.produkteDetailVC = produkteDetailVC;
[self.produkteSplitVC setViewControllers:[NSArray arrayWithObjects:produkteMainNavigationController,self.produkteDetailVC,nil]];
thanks for all help!
edit:
its exactly 20px like the statusbar. does that help anyone?
edit2:
doing something like this:
if(self.navigationController.navigationBar.frame.origin.y >= 20.0) {
self.navigationController.navigationBar.frame = CGRectMake(self.navigationController.navigationBar.frame.origin.x, 0.0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height);
}
results that:
a little improvement i would say. but i have no idea how to stick my tableview underneath the navigationbar.
I know this is a very old topic but maybe it'll help other people...
I had the same issue (with the same configuration : splitview in tabbar).
This property solved it !
[self.splitViewController setWantsFullScreenLayout:YES];
UINavigationController has a nasty habit of shifting its contents down by 20px, depending where you place it. I'm guessing it's doing it here because your split view controller is inside of a tabbar controller, and Apple has not blessed this type of arrangement.
I've run into this same issue, with out a resolution. The only thing I've noticed is this does NOT happen when the master does not include a UINavigationController as its root.
Anyone figure a solution to this?
Here's what I did, and it seems to work fine.
I created my own custom tab-view controller, derived from UIViewController. In viewDidLoad I add a UITabBar to the bottom of the view and set the delegate to myself so I can handle tab changes. (I return this UITabBar as the rotatingFooterView) Tab changes result in swapping the current view controller, just like a real UITabBarController. When swapping view controllers (sometimes a UISplitViewController, hosting a UINavigationController in the master view), I add and position the view-controller's view within my view, above the UITabBar. I'm also careful to forward viewWill/DidAppear/Disappear calls to the current view controller, as well as each of the will/didRotate messages.
seems that this problem occurs from iOS 7.0. Setting the frame of UINavigationBar in some cases doesn't work. I think this can solve your problem :
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
self.navigationController.view.frame = CGRectMake(0, -20, self.navigationController.view.frame.size.width,
self.navigationController.view.frame.size.height);
}
This code should be called only once (for example in - (void)viewDidLoad ).
In my case it works for all device orientation.

MKMapView not allowing user interaction on Ipod Touch OS 3.1.3, works correctly on simulator 3.2 / 4.0

I have been coding and testing an app which uses a navigation controller, tab bar and table views together as shown in this tutorial video:
I have also coded a MapView page which shows custom annotations. This seems to work fine in every version of the simulator I have tried it on. This morning I have finally got the app running on my Ipod Touch which runs OS 3.1.3 - everything works as expected except the map does not seem to allow user interaction at all. I cannot tap on annotations, the current location or move and zoom at all.
I have been through all the settings in the Interface Builder for the mapview, and made sure that all the 'User Interaction', 'Allow Multitouch' boxes have been ticked. This doesn't seem to change anything.
Any help greatly appreciated.
The Mapview is put into the view as follows:
// Grab the maps view controller ready for loading
MapView *childController = [[MapView alloc] initWithNibName:#"MapView" bundle:nil];
childController.title = #"View on Map";
// Push the new view controller onto the stack
[self.navigationController pushViewController:childController animated:YES];
[childController release];
childController = nil;
I've also tried running the view in a modal view controller just to see what would happen. The view was shown and any interaction didnt seem to work - with the exception of a small section at the bottom where I made the view itself slightly shorter so it would fit in above the tab bar. This section seems to have another map underneath my view which DOES respond to user interaction. So there is a 1cm or so block which does move - my view seems to stay static on top of it, though.
The view underneath does not appear to have any annotations or the current user location.
Ok I've solved this one:
In the mapview.m file where I set up the view and load the annotations, within the viewDidLoad function I had the following code:
- (void)viewDidLoad {
// More code before this..
[mapView addAnnotations: eventPoints];
// This is causing the problems on the ipod touch.
// The view is added ON TOP of the first map..
//[self.view addSubview:mapView];
self.view = mapView;
// More code after this..
}
Where mapView is
IBOutlet MKMapView *mapView;
Adding a subview on top of the current view didn't want to work. Actually setting the view to be the new updated view with annotations seems to work fine. It's still strange that the simulator would work and not the device in the first place though.
Hope this helps someone.