从主视图控制器知道所呈现的模态视图控制器何时被关闭?

发布于 2025-01-04 20:33:02 字数 168 浏览 0 评论 0原文

我想知道是否可以从视图控制器知道其呈现的模式视图控制器何时被解除? (即当它的视图返回时?)

我尝试过:

viewWillAppear
viewDidAppear

但是,这些似乎不起作用:(

任何人都可以提出建议吗?谢谢。

I wanted to know if its possible to know from the view controller when its presented modal view controller is dismissed ? (i.e. when its view returns?)

I tried:

viewWillAppear
viewDidAppear

But, these didnt seem to work :(

Can anyone kindly suggest ? Thanks.

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

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

发布评论

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

评论(1

月依秋水 2025-01-11 20:33:02

这是一个回调解决方案,它对模态和父级进行较少的修改:

在模型的 .h 添加:

@property (nonatomic, copy) void (^dismissed)();

在模型的 .m 中,当您关闭模态时,将其放入完成中:

[self dismissViewControllerAnimated:YES completion:^{
    if(self.dismissed)
        self.dismissed();
}];

在父视图控制器中,当您实例化模态时,设置关闭打回来:

Modal = //Init your modal
[Modal setDismissed:^{
    //do stuff you wanted when it's dismissed
}];
[self presentViewController:Modal animated:YES completion:nil];

Here's a callback solution which takes less modifications to your modal and parent:

In the Model's .h add:

@property (nonatomic, copy) void (^dismissed)();

In the Model's .m put this in the completion when you dismiss the modal:

[self dismissViewControllerAnimated:YES completion:^{
    if(self.dismissed)
        self.dismissed();
}];

In the parent view controller when you instantiate your modal set the dismissed callback:

Modal = //Init your modal
[Modal setDismissed:^{
    //do stuff you wanted when it's dismissed
}];
[self presentViewController:Modal animated:YES completion:nil];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文