My app should display a login modal view, and once authentified, redirect on a SplitView.
For now, i'm using the method that change the rootView in the app delegate. So, in the loginController, i do this :
[[[[UIAppDelegate window ] subviews] objectAtIndex:0] removeFromSuperview];
And after that, i load my splitViewController and place it in the rootViewController property.
It's working. But i would like to make a transition between the two views, and i've absolutely no idea how to make this happen.
Any clue ?
Thanks
see this question Best way to switch between UISplitViewController and other view controllers?
It seems that you should show login view as a modal view over split view
Related
On my main view in a NavigationController I have a button that brings up a new view modally to submit a post. I have a button to dismiss this view which brings the user back to the main view, however if the users proceeds to make a post, I want it to dismiss the view and proceed to a show the post in the Navigation controller.
The ideal effect would have the standard navigation controller's back button on the top that can bring the user back to the main view when they have finished looking at their post.
I have tried several different methods, but I tend to get an error stating "Warning: Attempt to present (The View I Want to Show) whose view is not in the window hierarchy!
Thanks for any info!
Yes, it's possible. This is the best way I've found to structure the app to allow this functionality.
RootViewController
UINavigationViewController
ContentViewController (your current "main" view controller)
You're basically going to create a new RootViewController that is going to contain your current UINavigationController as a child. I usually setup the window.rootViewController programmatically in the AppDelegate. I would also keep a global reference to it.
Have a look at Apple's documentation on this. Basically, the RootViewController code would look like this:
[self addChildViewController:navController];
navController.view.frame = self.view.bounds
[self.view addSubview:self.navController.view];
[navController didMoveToParentViewController:self];
Now, whenever you need to present a modal view controller, present it from the RootViewController, instead of the current/top view controller on the UINavigationBar. This allows you to manipulate the UINavigtaionController independently and you won't get the error you're seeing.
So present the modal view controller from the RootViewController, this covers the UINavigationController and its content (top view controller). Make any changes you need to the UINavigationController stack (push, pop, etc...) with no animation. When you're done dismiss the modal view controller (with animation) and it will show you're adjusted UINavigationController.
Hopefully, this all makes sense. It's kind of complex and hard to explain in text. :p
If you don't want to setup a RootViewController, you might want to try presenting the modal view controller from the UINavigationController, as that might have the same effect. From the view controller just do self.parentViewController.present.
The main thing you're trying to avoid is presenting a modal from a view controller and then removing that view controller (pop) before the modal is dismissed. The view controller that presents the view controller is responsible for dismissing it.
I finally got it all working (I'm still new to Swift) and the two comments on the question were very helpful. The most helpful of all was the top answer here's example on github.
Similar question
I have an app which has tab bar controller as main controller. Each tab has a series of views with navigation controller and I normal push and pop those view in stack.
Weird problem is
Case 1 : If I create a UINavigationController and make a new viewController as its root, and present this NavigationController. Within this new navigation stack, I can easily present a view modally and dismiss it without a problem.
Case 2: Now without make a new UINavigationController, I present a view, and when I dismiss a view, the view beneath is behave weirdly. For example, it's the presenting view was UICollectionView, it just scroll back to 1st cell, like it's doing "reload" action and "scrollTo" the first cell. If the presentingView is a pushed view from rootView, it will just popToRoot view, which is definitely not intended.
I didn't have this problem until I implement UITabbarController, so I guess, I should know more that's going on under the hood when presenting a view and dismiss a view in UITabbarController.
I GUESS, when dismiss a view in UITabbarController view, it sort of "RESET" everything to the very first view of it's current tab. I really am not sure it's trure though.
I know it's kind of conceptual, but I can't help to think there must be something critical I am missing here.
I made silly mistake that I sublclass UITabbarController and define navigation controlllers in viewDidAppear instead viewdidLoad, so when I make the window's rootview to tabbar controller, the navigation controllers are not set properly. That's why all punky things happened. It would be nicer if just crash instead of this weird behaviors.
You can try this to go back to your first viewcontroller.
- (IBAction)buttonPressedFromVC2:(UIButton *)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
} // This is going back to VC1.
This method is will be in second viewcontroller.m file. It is button click method.
What I'm trying to do
If started creating my App. I've got a NavigationController as my rootViewController. When the app is started it will open my LoginViewController. In there I do the Login-Procedure, if everything is fine. I'll start my ECSlidingViewController. Which has a Menu (UITableView) and a MainView (UITableView).
Until here everything is working fine. I can swipe and it show's my menu. Now the problem is starting. When I press a menu-item it perfectly starts my new ViewController and show's the content. But there it still show's the same NavigationBar - like in the ECSlidingViewController. So I got no possibility to tell the user what he is looking at, also I need to show him sometimes new options in the NavigationBar.
Question
How can I fix this problem? I'd always like to show the NavigationBar of the specific ViewController I'm actually using. If you guy's have some Codesnippets or a good Idea how to handle this problem. Please leave a comment bellow.
If you need codesnippets or something else, tell me I'll upload it! Thank you in advance!
Code
This is how I start my ECSlidingMenu:
[self performSegueWithIdentifier:#"loginPush" sender:self.view];
This is how I'll start a new ViewController:
UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
Pictures*
You want to change your structure so that the ECSlidingViewViewController is the root view controller. This can either be from the start of the app or you can switch the root after login. The top view controller of the sliding controller should then be a navigation controller and you should set the root and push other view controllers into that navigation controller.
What you currently have breaks the link between the view controllers and the navigation controller because only the sliding view controller is pushed into the stack and its title (nothing about its navigationItem ever changes).
Probably the easiest solution would be to change the initial view controller in the storyboard (to the sliding view controller). In this case the login view would be presented as the root view of the navigation controller (which would be the top view). Then, after login you push the next view controller and then (after the animation completes) remove the login view controller from the nav stack.
I have a login screen which redirects to home page after a successful login.
I redirect like this:
ViewController *viewController = [[UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:#"main"];
[self presentModalViewController:viewController animated:YES];
and the redirection happens, and the home screen loads, but the buttons on it no longer respond to clicks, and the nav area is missing.
I am using push segues.
Would anyone know why this sort of thing happens? Also, right now I am using push segueys, but should I be using a modal seguey?
My functionality is: do some logic on one screen, go to the next screen.
First, I would create the entire "redirecting" differently. In IB, select the login view controller and drag from it to the home screen view controller and choose Push. Select the segue and add identifier and replace your redirect method with
[self performSegueWithIdentifier:#"identifier set in IB" sender:self];
You need to understand better how UINavigationControllers work. The reason the buttons arent working is that you have put them on the UINav controller itself and not on the "implied" toolbars that are associated with the view.
UINavigationController swaps out its controls with the controls of the pushed view. If you put controls directly on the UINav controller, your viewController will not get the associated messages.
UINavigationController is a container for views thats it. Go into IB and put your buttons on the toolbar of the views inherited toolbars and it will work.
This actually happend to me also. What happend was in my case, there was an option called Initial View in the Attributes Inspector. Keep it so that option is checked only for the UINavigation controller itself.
Try that. If it doesn't work, sorry :/
Edit: this is a question I posted a while back for bounty and it details this same problem. Check out the answer.
Are you sure that the View has it's userInteractionEnabled?
[self.view setUserInteractionEnabled:YES];
Just looking for some advice. What is the best way to present a full screen modal view controller from a UISplitViewController (set as the root) ?
There's no difference presenting a modal view controller from a UISplitViewController that from any other UIViewController.
You simply call - (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated.
Do you know how to make a full screen controller?
Do you know how to present a modal view controller?
Are you having any problem combining the two?
Try it and if you have a specific problem ask about that.