[英]iOS presentViewController doesn't invoke viewDidLoad
I'm implementing my own 'back' button. 我正在实现自己的“后退”按钮。 Where
onClick
, the following code is executed in the ViewController
(VC) being dismissed: 在
onClick
,以下代码在被解除的ViewController
(VC)中执行:
navigationStack
navigationStack
navigationStack
, and present it using navigationStack
获取最后一个VC(VC#2),然后使用它 presentViewController presentViewController
What happens is the back works visually works - ie current VC
disappears, previous VC
appears. 后面的工作是视觉效果 - 即当前
VC
消失,之前的VC
出现。 However, the viewDidLoad
method is not called. 但是,不会调用
viewDidLoad
方法。 So the screen isn't updated with data updates from viewDidLoad
. 因此,不会使用
viewDidLoad
数据更新来更新屏幕。
[self dismissCurrentViewController:self completion:^{
[TWStatus dismiss];
FHBaseViewController *vcToDisplay = [[FHDataManager sharedInstance] popNavigationStack];
[vcToDisplay.homeVC presentViewController:vcToDisplay animated:NO completion: ^{ }];
}];
Questions: 问题:
viewDidLoad
always gets called when presentViuewController
is used?? presentViuewController
时, viewDidLoad
总是被调用? viewDidLoad
in VC#2. viewDidLoad
中名为ONLY的方法“构建”屏幕。 How is iOS displaying the screen without coming into viewDidLoad
? viewDidLoad
情况下显示屏幕? btw, I'm not using storyboards. 顺便说一下,我没有使用故事板。 Any help is appreciated!
任何帮助表示赞赏!
My guess is that viewWillAppear
is being called but viewDidLoad
is not, at least not when you expect it is. 我的猜测是调用
viewWillAppear
但是viewDidLoad
不是,至少不是你预期的那样。 viewDidLoad
should be called once, but depending on how you're managing the view controllers, viewDidLoad
may not be triggered every time your view appears (which happens after loading). viewDidLoad
应该被调用一次,但是根据你管理视图控制器的方式,每次你的视图出现时都可能不会触发viewDidLoad
(加载后会发生这种情况)。
The completion handler is called after the viewDidAppear: method is called on the presented view controller.
from presentViewController doc 来自presentViewController doc
so put this in your code with a breakpoint on the call to super
and verify it is getting called when this transition occurs. 所以把这个放在你的代码中,在调用
super
时使用断点,并在发生此转换时验证它是否被调用。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
edit : since you verified that viewWillAppear
is getting called, then I would say that it's coming down to how you are managing the view controller life cycle. 编辑 :既然你已经验证了
viewWillAppear
被调用了,那么我会说它是关于如何管理视图控制器生命周期的。 Even with a standard UINavigationController
, viewDidLoad
is not called when a view is shown as a result of popping items on the navigation stack. 即使使用标准的
UINavigationController
,当视图显示为导航堆栈上弹出项目的结果时,也不会调用viewDidLoad
。 I would move your logic to viewWillAppear
if you are dead set on not using UINavigationController
如果您没有使用
UINavigationController
我会将您的逻辑移动到viewWillAppear
When I make a back button pragmatically I use: 当我务实地制作后退按钮时,我使用:
[self.navigationController popViewControllerAnimated:YES];
This will invoke the viewDidLoad method. 这将调用viewDidLoad方法。 Use that instead of your current code.
使用它而不是您当前的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.