How to identify the class of a Modal View controller? - iphone

In my application, I have to present two modal view controllers one above the other.
Lets say Modal View Controller B is placed over Modal View Controller A. Sometimes, there will be only A and no B.
I want to check from A that whether the top Modal View Controller is B. I know there is a method NSStringFromClass() but I can apply that only if I get the top Modal View Controller.

use (BOOL)[[youObjectInstance isKindOfClass:[ControllerClassYouWantToCheckAgainst class]]
Documentation here:
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/isKindOfClass:

Related

Push from one view controller to another

I have a tricky situation. The following is the hierarchy of the views that I have.
(Root)Navigation-VC-->View A-->(via Segue push)--> View B-->View C
(Root)Navigation-VC-->View A-->(via modal push)-->(Nav Controller) View D-->View E
There is a cancel button in view D. When I click on it, it correctly shows view A. But For some reasons I would want it to go to View B in the first navigation hierarchy. How can I do such transitions?
If I create a modal segue from view D to view B it destroys the navigation hierarchy that view B is part of. If I push view B from view D then view B becomes a part of a different hierarchy altogether.
Can it be done? Do I have to rethink the design?
Well, after you dismiss the modal view controller, you can always call the method performSegueWithIdentifier:sender: to push view B. Just remember to set the segue identifier in your storyboard.
Call the method dismissViewControllerAnimated:completion: in view A and call the perform segue at the completion block. This is just to avoid any corruption that might happen to the navigation controller if you dismiss and perform segue at the same time.

dismissModalViewController issue in iOs

I have three view controllers, say A, B and C. I am navigating through this views like follows;
A -presenting-> B -presenting-> C -presenting-> B
And from B, if I dismiss I want to navigate to C. But instead of that, now it is moving to A. I can't use dismiss for navigation from C to B (some internal issues). So how can I fix this? Please help.
You hit into a limitation of dismissModalViewController: it will remove all of your modal views (source):
If you present several view controllers in succession, and thus build a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
What you could do is using a UINavigationController and simply push/pop controllers on to it according to your requirements.
Alternatively, you could simply display the views managed by the various controllers you have by directly calling addSubview on your top view and making sure they cover the whole screen and that the managing controller is correctly retained/released (the view is automatically when you add/remove it to another view).
As a hint, you could do it like this:
where you have presentModal..., use addSubview;
where you have dismiss..., use removeFromSuperview;
store a reference to any view controller whose view you manage like I suggest here in retain/strong property.
Hi use the below code in "C" viewcontroller
[[[self presentingViewController] presentingViewController] dismissModalViewControllerAnimated:YES];

How can I dismiss several controllers ?

Using storyboard , I'm invoking a segue (set type to modal) in order to display the second controller , and the same way to display the third controller. A->B->C. I expect dismiss B and C together , and return to A. There was no navigation view controllers , no popToRootViewControllerAnimated: .
In docs:
If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
I tried a variety of ways but failed. Am I missing something really simple ?
Try This
[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES]
Also try This
[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];

hide Split view only in one particular View Controller

I have one SplitView controller which i have set in Application Delegate class.
Now I want to do that I want to hide Split view only in one particular view controller other wise it will be shown.
I know the method to hide split view but it will be hidden or shown in all the view controller how can i do that for particular one view Controller.
-Thanx in advance

How to know - view controller's current view in iphone

Let's have an example.
In application I have a tab bar controller.
Tab bar has two items dynamically - two view controllers.
User can select any of tab.
Suppose user selects first tab.
First view controller is already loaded.
Now he clicks on a button of First view controller.
From First View controller -> Second View controller is pushed.
Now when user taps on tab bar first item
second view is popped out.
This is done through by default by tab bar controller.
Now, If I want to check following condition
if(tab bar first item-view controller has first view controller view)
then perform this
if(tab bar first item-view controller has second view controller view)
then perform this
How to implement this logic?
If you are using a UITabBarController, you can use its selectedViewController property to know what kind of view controller is on the screen, so if you have two subclasses of view controller FirstViewController and SecondViewController you can say
if([[tabBarController.selectedVIewController isKindOfClass:[FirstViewController class]])
//... do something
else ...