Вопрос

My UIViewController stack looks as follows:

+------ UIViewController_C (presented)
+---- UIViewController_B (presented)
+-- UIViewController_A (pushed)

When I call -dismissViewController:animated on UIViewController_C, UINavigationController dismisses both UIViewController_C and UIViewController_B together, as per the docs with animation on _C, and none on _B.

What is the most compliant way to dismiss _C only?

Это было полезно?

Решение

try as below

after pushing to UIViewController_A present UIViewController_B as below code.

UIViewController_B *bbp=[[UIViewController_B alloc]initWithNibName:@"UIViewController_B" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
passcodeNavigationController.navigationBar.hidden=YES;
[self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
[passcodeNavigationController release];

now from UIViewController_B try to present in UIViewController_C as below code.

    UIViewController_C *bbp=[[UIViewController_C alloc]initWithNibName:@"UIViewController_C" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
passcodeNavigationController.navigationBar.hidden=YES;
[self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
[passcodeNavigationController release];

last and final thing on every back button of view controller write below line of code.

[self dismissModalViewControllerAnimated:YES];

if you want more help than comment bellow.

Другие советы

One Solution:

UIViewControllers presented modally are not necessarily deallocated on -dismissViewController:animated.

This means that by passing a reference to UIViewController_A through _B to _C, you can call -presentViewController:animated and -dismissViewController:animated for the respective UIViewControllers via UIViewController_A.

Code:

1. UIViewController_B

- (void) showUIViewController_C {

    [self dismissViewControllerAnimated:TRUE completion:^{
        UIViewController_C *controller_C = [[UIViewController_C alloc] init];
        controller_C.parentController = self;
        [self.parentController controller_C animated:TRUE completion:nil];
    }];
}

2. UIViewController_C

- (void) dismissUIViewController_C {

    [self dismissViewControllerAnimated:TRUE completion:^{
        [self.parentController.parentController presentViewController:self.parentController animated:TRUE completion:nil];
    }];
}

Where I am using *parentController as the naming convention for whatever class your previous UIViewController on the stack may be.

It dips back to UIViewController_A briefly because I am calling -dismiss and -present in the completion block, though that actually looks rather fun.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top