iOS 5 split view modal view controller popup: possible or no dice? - ipad

I basically have a splitview controller and immediately I would like to show a popup modal view controller.
I have wired up the UISplitView class with a modal segue to my other view controller (LoginView, just a straight UIViewController subclass) I basically just want to show that on load and I'm pretty sure I shouldn't do this in the app delegate (however I could be wrong)
I want to do it with a
[something performSegueWithIdentifier:#"login" sender:something];
Where should I put it and what should I connect the segue to (I swear I have tried every different combination haha!)
(I'm using the universal master-detail view starting project from Xcode 4.2)

I would display this from your initial detail view controller (the right pane of your split view) since it will always be sent a -viewDidAppear: message regardless of launch orientation.
In your -viewDidAppear: method, have the split view controller present the modal controller. Each view controller in a split view controller will already have its splitViewController property set. Ensure that your segue is connected from the split view controller (not one of its child view controllers) to the login view controller.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.splitViewController performSegueWithIdentifier:#"login" sender:self.splitViewController];
}

Related

Login Modal view not showing over a splitview using Xamarin iOS and MVVMCross

I'm working on an iPad app using splitview controller and MVVMCross which requires a login screen. I'd like the login screen to appear as a modal popover in the centre of the screen, over the top of the underlying screen which is controlled by a UISplitViewController.Ideally I'd like the 'master' view to be hidden and then appear after a successful login. I understand my UISplitViewController has to be the root controller, so I need to launch the popover from either the master or detail view at an appropriate event
General iOS modal views:
When doing modal views, I tend to do something like this inside the view that we want to be the parent of the modal view.
var myViewController = new UIViewController();
var myModalNavigation= new UINavigationController(myViewController)
{
ModalPresentationStyle = UIModalPresentationStyle.FormSheet,
ModalTransitionStyle = UIModalTransitionStyle.CoverVertical
}
this.PresentModalViewOnTop(myModalNavigation);
We create our view controller, then a navigation controller using the view controller. We give the nav controller a modal presentation and transition style. Then inside the view controller that will launch the modal view we call this.PresentModalViewOnTop();.
In your case in particular, you'd probably want to do this code from your "master view". But you can make it do that inside ViewDidLoad to ensure they can't use your "master view" until the modal has been satisfied and disappeared.
Modal views in MvvmCross:
You'll need to change your presenter logic as MvvmCross assumes every view model is just a normal full "page". There is a great explanation of how to do this here: How do I specify a view to be pushed as Modal in MvvmCross?

warning attempt to dismiss from view controller while a presentation or dismiss is in progress

Steps to reproduce -
Open Modal view controller on tap of button of Root View controller.
In Modal view controller - On button, create segue to show popover view controller.
Tap on button to see Popover view controller.
Now multiple taps on screen to dismiss the popover view controller, it directly redirects to Rootview controller.(dismissing the Modal view controller).
Another approach -
Create IBAction to show popover view controller.
Tap on button to see Popover view controller.
This time it just dismiss the pop view controller. (Not redirecting to RootView controller)
Why this weird behavior when your showing Popover view controller in two different ways?
I am working on already developed big project and now its not possible for me to go ahead with second approach.
Please help me to find out the better way to resolve this.
You will need to create a delegate method in your Modal view controller.
After your popover view controller dismissed, then call your Modal view controller delegate method to dismiss as well.
[self dismissViewControllerAnimated:YES completion:^{
ModalViewControllerDelegate.dismissView;
}];

UISplitViewController and Modal view controller presentation issues

I am having troubles with an application where I have a split view controller and would like to display a modal view controller over the top.
To test this, I have created a basic project which mimics the structure of my application. I have uploaded this to Github for anyone to download: https://github.com/CaptainRedmuff/SplitViewDemo
There are two main issues which I will detail below:
Issue 1:
When presenting the modal view controller in portrait orientation with the master view controller visible (as a popover I believe), the modal view controller is displayed underneath the master view controller. Any attempts to interact with the model view controller cause the app to crash.
Issue 2:
When presenting the modal view controller from the tab bar controller (in the master view controller), the modal view controller is automatically dismissed when the device is rotated to landscape orientation as the master view controller is removed from the hierarchy.
One possible fix I have found is to conform to the UISplitViewControllerDelegate method - (BOOL)splitViewController:shouldHideViewController:inOrientation: and return NO to force the master view controller to always be visible. This is not the behaviour that I want however so this is not a viable fix.
Considering that there is no way to programatically display or dismiss the master view controller, I am at a loss for alternative methods to present a view controller modally over the top of the entire split view controller.
Before presenting modal VC you must dismiss popover like:
[self.popover dismissPopoverAnimated:NO];
The issue occurred probably because UIPopoverController is added to the window instead of UISplitViewController.

going back inside navigation controller through embedded view controller

In my iOS project I have a main menu that is shown embedded in a container in my initial UIViewController.
After the user choses any row in that menu, the navigation controller pushes the submenu viewController that manages further actions, which uses the full window.
If the user wants to go back to main screen, he taps "back" button and my navigationController pops back. But when it should pop to the main viewController it fails to restore the view of my initial viewController.
Do you have any clue how to pop back to the first viewController in navigationViewController hierarchy if that view controller has containers with embedded view controllers in them?
Or should I consider changing the architecture of my storyboard?
The fact that the view controllers in a navigation controller have child view controllers is not important. Only worry about the top-level view controllers that are pushed onto the navigation controller's stack. And only push/pop top-level view controllers, not children.
If you are having problems, you are probably doing something wrong, and will need to post a screenshot of your storyboard, along with the code that shows how you manage your navigation controller stack.
If you want your initial view controller to contain the proper subviews, you either need to hide/show what you need to make it to look like you want in viewDidDisappear as the user moves on to a new view, or you need to set it when they come back in viewWillAppear.
However your view is set up when you leave is how it will show up when you come back unless you change it. For example, in your root view controller:
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// hide your menu, clean up the view to prepare it for when user pops back
}
OR
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// if menu is showing, hide it. Clean up view before user sees it
}

Visible View Controller after dismissing modal view

I would like to know why tha't happening: I have 2 view controllers embeded in navigation controller. All have superclass where I have something like that:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(#"Visible VC: %#",self.navigationController.visibleViewController.class);
}
So far everything works like a charm. Then I added third navigation controller which is the modal view controller. It also has super class like the others. Now I see strange thing. After click button to present modal View controller I see log: "Visible: (null)", but it's ok because third VC is not in navigation controller. When i click dismiss button to hide modal View controller I see 2 logs: "Visible: (null) Visible: ViewController3". My question is: Why visible view controller is not kind of class ViewController2 ? It should be, because third one was dismissed. How can i resolve it ? I need to have visible view controller kind of class View Controller 2.
I'm guessing that viewController2 is not the visible one yet when that is called.
Try accessing it in
viewDidAppear
instead of viewWillAppear.
Or, you can try to access the
self.navigationController.topViewController
property instead, that should return viewController2.

Resources