Visible View Controller after dismissing modal view - ios

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.

Related

Dismiss Modally presented view makes tab bar controller (kind of) reset

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.

navigation Done item not working

in the top view of my view controller (the last table view controller) has an add navigation item. i added a view controller object from the objects library and i ctrl + dragged from the plus button to the view controller. i tried the app and it works fine but i can't go back to the previous controller when i reach the last controller. since the last controller connected (by segue) to the plus button, i can't have a navigation bar on top. so i added one and added an navigation item called it Done. i created an IBAction method in the class that the last controller subclasses which have the following code:
[self.navigationController popNavigationControllerAnimated:YES];
However, when i run the app and press the Done button to go back, it doesn't work although i feel like what i did is totally legal.
If you would have made the final view controller segue a Push segue, you'd still have the navigation bar with a back button. It makes sense since you're adding a record that you'd want a modal view.
You can dismiss the current modal view with the following code:
[self dismissViewControllerAnimated:YES completion:nil];
Generally, you should use delegation and dismiss it from the presenting view controller. However, I think it's fine to dismiss yourself if you're using storyboards, segues, and ARC.
Did you create a Bar Button Item and assigned its 'selector' callback?

How to dismiss a NavigationController in Storyboard?

I've looked everywhere for this, so as a last resort I figured I should ask the question.
I'm using Storyboard in XCode and have a navigation controller as my initial view. The root view of this navigation controller is a table view. In this table view, I have a button in the navigation bar that flips the view horizontally via a modal segue to a navigation controller. The root view of this controller is my map view. Now, when I want to dismiss this map view using [self dismissViewControllerAnimated:YES completion:nil] it doesn't work. It does if I take out the navigation controller. So, I'm guessing the dismissViewController is getting passed to the navigation controller, and not doing anything. I know I could implement a class for the navigation controller to handle the call and pass it on, but I don't want to do that unless absolutely necessary.
So to solve this question:
I need a way to switch between table view to map view using the flip horizontally animation and vice versa.
I need to have a navigation controller in both views, I could either be the same one, or a different one. I can't seem to find a way to use the same one, since any transitions would be pushes which don't do the flip horizontally transition.
Thanks in advance for the help!
Who is self when you call [self dismissViewControllerAnimated:YES completion:nil]?
The receiver of this message needs to be the view controller which presented the modal view controller you want to dismiss. If you call it on the presented view controller, or (in the case of container view controllers like UINavigationController, one of the view controllers it manages), UIKit will try to do the right thing but won't always succeed.
Presuming the self you refer to is the view controller containing the map view, you can get the presentingViewController property to get the object you should call dismissViewControllerAnimated:completion: on. (And if you need to get the navigation controller that's in between, use the navigationController property.)

Can't instantiate new controller

I would like to load a new ViewController/View upon validation of a login username/password. I have the following:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
...
...
ViewController *Workflow = [self.storyboard instantiateViewControllerWithIdentifier:#"Workflow"];
[self.navigationController pushViewController:Workflow animated:YES];
Then, in the story board, I added a new view controller and slapped a new uiview on there. I then changed the identifier of the ViewController to "Workflow". However, after clicking this button, nothing happens. Any ideas?
I would first NSLog the index of the button sending you the action, it's extremely useful for long alerts, and delegate methods with switch statements. If nothing is happening, then nothing is usually being done.
It sounds like you could be missing a UINavigationController from your storyboard. Unless your view controllers live within a UINavigationController, pushViewController: will have no effect.
If this is the case, what you need to do is:
Drag an instance of UINavigationController from the objects library onto your storyboard. Delete the root view controller that comes with it.
With the Navigation Controller selected on the storyboard, click the checkbox named "Is Initial View Controller" on the Attributes Inspector.
Hold down the Control key on your keyboard and drag with the mouse from the Navigation Controller to your first view controller (presumably the one where you are displaying the alert view) to create a segue. In the Storyboard Segues box that appears after you release, select "Relationship - Root View Controller"

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

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];
}

Resources