gpt4 book ai didi

ios - 如何检测是否从导航 Controller 弹出 View Controller ?

转载 作者:IT老高 更新时间:2023-10-28 11:47:34 26 4
gpt4 key购买 nike

当顶 View Controller 从我的导航 Controller 中弹出时,我目前需要实现一些代码。有没有办法检测 View Controller 何时从导航 Controller 堆栈中弹出?

我想尽可能避免使用 viewWillDisappearviewDidDisappear 因为我在我的项目中使用了 splitview,并且在主视图中选择不同的行也会触发 viewWillDisappear/viewDidDisappear 方法。

最佳答案

您可以使用 View Controller 的 isMovingFromParentViewController 属性检测是否正在弹出 View ,如下所示:

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if ([self isMovingFromParentViewController])
{
NSLog(@"View controller was popped");
}
else
{
NSLog(@"New view controller was pushed");
}
}

isMovingFromParentViewController

Returns a Boolean value that indicates that the view controller is in the process of being removed from its parent.

关于ios - 如何检测是否从导航 Controller 弹出 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21915249/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com