如何关闭两个或多个dismissModalViewController?

发布于 2024-10-04 08:13:25 字数 417 浏览 2 评论 0 原文

我需要关闭两个模态视图控制器,我知道如何弹出两个或多个视图控制器

        UINavigationController* navController = self.navigationController;
    NSArray *array=[navController viewControllers];
    UIViewController* controller = [navController.viewControllers objectAtIndex:0];
    [navController popToViiewController:controller animated:YES];

这是我导航回第一个视图的方法,但如果有两个或多个关闭模态视图,那么我如何导航回来,

请帮助我, 谢谢你, 马丹·莫汉

I need to dismiss the two modal view controllers, I know how to pop two or more view controllers

        UINavigationController* navController = self.navigationController;
    NSArray *array=[navController viewControllers];
    UIViewController* controller = [navController.viewControllers objectAtIndex:0];
    [navController popToViiewController:controller animated:YES];

This is how i can navigate back to my first view but if there are two or more dismiss modal view then how can i navigate back

please help me,
Thank you,
Madan Mohan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

墨小墨 2024-10-11 08:13:26
UINavigationController* navController = self.navigationController;
NSArray *viewControllers=[navController viewControllers];
UIViewController* controller = [viewControllers objectAtIndex:0];
[navController popToViewController:controller animated:YES];

如果你在上面的代码中将对象设置为索引 0,它会带你到第一个视图,这是一个推送视图控制器。

1)Rootview--->moodalview1--->moodalview2--->moodalview3 如果您使用上面的代码,那么您将处于根视图中。

2)Rootview--->Pushview1---->moodalview1--->moodalview2---->moodalview3。如果您使用上面的代码,您将进入 PushView。

UINavigationController* navController = self.navigationController;
NSArray *viewControllers=[navController viewControllers];
UIViewController* controller = [viewControllers objectAtIndex:0];
[navController popToViewController:controller animated:YES];

if you set the object at index 0 in the above code its gonna take you to first view which is a push view controller.

1)Rootview--->moodalview1--->moodalview2--->moodalview3 if you use above code then you wiil be in root view.

2)Rootview--->Pushview1---->moodalview1--->moodalview2----->moodalview3. if you use above code you will be in the PushView.

始于初秋 2024-10-11 08:13:26

对于 iOS 5,支持 animation==YES (视图将按顺序隐藏)和 completion 块:

+ (void)dismissAllVCsForVC:(UIViewController *)VC animated:(BOOL)animated completion:(BPSimpleBlock)completion {
    if (VC.presentedViewController == nil) {
        if (completion) {
            completion();
        }
    } else {
        [BaseViewController dismissAllVCsForVC:VC.presentedViewController
                                        animated:animated
                                      completion:
         ^{
             [VC dismissViewControllerAnimated:animated completion:completion];
         }];
     }
}

For iOS 5, support of animation==YES (views will hide in sequence) and completion block:

+ (void)dismissAllVCsForVC:(UIViewController *)VC animated:(BOOL)animated completion:(BPSimpleBlock)completion {
    if (VC.presentedViewController == nil) {
        if (completion) {
            completion();
        }
    } else {
        [BaseViewController dismissAllVCsForVC:VC.presentedViewController
                                        animated:animated
                                      completion:
         ^{
             [VC dismissViewControllerAnimated:animated completion:completion];
         }];
     }
}
牛↙奶布丁 2024-10-11 08:13:25

-[UIViewController DismissModalViewController] 的文档中:

如果你呈现几个模态视图
连续控制器,因此
构建模态视图堆栈
控制器,在
查看堆栈中较低的控制器
忽略其直接子视图
控制器和所有视图控制器
在堆栈上那个孩子的上方。什么时候
发生这种情况,只有最顶层的视图
以动画方式被解雇;
任何中间视图控制器都是
只是从堆栈中删除。这
最顶层的视图被使用它的
模态转换风格,这可能
与其他人使用的风格不同
堆栈中较低的视图控制器。

From the docs for -[UIViewController dismissModalViewController]:

If you present several modal view
controllers in succession, and thus
build a stack of modal 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.

情栀口红 2024-10-11 08:13:25

使用下面的代码

[[[self presentingViewController] presentingViewController]  dismissModalViewControllerAnimated:YES];

Use this below code

[[[self presentingViewController] presentingViewController]  dismissModalViewControllerAnimated:YES];
初见 2024-10-11 08:13:25

我使用以下实用程序静态方法来模拟 popToRootViewController 的模态堆栈:

// Util.m
+ (void)popModalsToRootFrom:(UIViewController*)aVc {
    if(aVc.parentViewController == nil) {
        return;
    }
    else {
        [Util popModalsToRootFrom:aVc.parentViewController];  // recursive call to this method
        [aVc.parentViewController dismissModalViewControllerAnimated:NO];
    }
}

您可以像这样使用它:

[Util popModalsToRootFrom:aViewController];

如果您想要更高级的东西,您可以这样做:

+ (void)popModalsFrom:(UIViewController*)aVc popCount:(int)count {
    if(aVc.parentViewController == nil || count == 0) {
        return;
    }
    else {
        [Util popModalsFrom:aVc.parentViewController popCount:count-1];  // recursive call to this method
        [aVc.parentViewController dismissModalViewControllerAnimated:NO];
    }
}

然后将模态数量传递给 pop,或者只是 -1 来弹出所有通往根源的道路。

I use the following utility static method to simulate popToRootViewController for a stack of modals:

// Util.m
+ (void)popModalsToRootFrom:(UIViewController*)aVc {
    if(aVc.parentViewController == nil) {
        return;
    }
    else {
        [Util popModalsToRootFrom:aVc.parentViewController];  // recursive call to this method
        [aVc.parentViewController dismissModalViewControllerAnimated:NO];
    }
}

You use it like this:

[Util popModalsToRootFrom:aViewController];

If you want something more advanced, you could do this:

+ (void)popModalsFrom:(UIViewController*)aVc popCount:(int)count {
    if(aVc.parentViewController == nil || count == 0) {
        return;
    }
    else {
        [Util popModalsFrom:aVc.parentViewController popCount:count-1];  // recursive call to this method
        [aVc.parentViewController dismissModalViewControllerAnimated:NO];
    }
}

Then pass the number of modals to pop, or just -1 to pop all the way to the root.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文