Bazinga
Bazinga

Reputation: 2466

UINavigationController to UIViewController difficulty

How to convert this for UIViewController is it possible:

for (UIViewController *tmpController  in [self.navigationController viewControllers]) 
{
    if ([tmpController isKindOfClass:[RootViewController class]])
    {
        [self.navigationController popToViewController:tmpController animated:YES];
        break;
    }
}

[self.navigationController viewControllers] --> how to convert this for UIViewController, because I'm having error,

[self.navigationController popToViewController:tmpController animated:YES]; --> while this part i convert it to this --> [self dismissModalViewControllerAnimated:YES];

Upvotes: 0

Views: 267

Answers (3)

Janak Nirmal
Janak Nirmal

Reputation: 22726

From the Comments above I feel like you are presenting controllers like From A to B and Than B to C.

Now you want to do from C to A to do that use following code

[self.navigationController popToRootViewControllerAnimated:YES];

EDIT

//Try this.
[[[self parentViewController] parentViewController] dismissModalViewControllerAnimated:YES];

Upvotes: 0

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

If you have ViewController A that presented ViewController B that Presented ViewController C

And you want to go back to A, do the following, in viewController C

[self dismissModalViewControllerAnimated:NO];
[[self presentingViewController] dismissModalViewControllerAnimated:NO];

Upvotes: 1

Nuzhat Zari
Nuzhat Zari

Reputation: 3408

You can get hierarchy of views as follows :

for(UIView *view in [self.view subviews])

Upvotes: 0

Related Questions