UIViewController:调用viewWillAppear,不调用viewDidAppear [英] UIViewController: viewWillAppear is called, viewDidAppear not
问题描述
在UIViewController子类中,我具有以下方法:
In a UIViewController subclass, I have the following methods:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// do something
myTextField.text = @"Default";
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// do something
[myTextField selectAll:self];
[myTextField becomeFirstResponder];
}
- (void)viewDidLoad {
[super viewDidLoad];
// do something
myTextField.delegate = self;
}
NIB是使用Interface Builder创建的.导航控制器通过pushViewController推送相应的视图控制器对象.
The NIB has been created using Interface Builder. The corresponding view controller object is pushed by the navigation controller through pushViewController.
实际行为是在文本字段中显示默认文本条目,选择整个文本并将该文本字段设置为第一响应者.
The inteded behavior is to show a default text entry in a text field, to select the entire text and to set the text field as first responder.
但是,虽然调用了viewDidLoad和viewWillAppear方法,但没有调用viewDidAppear方法.有人可以告诉我为什么吗?我在网络上发现的大多数问题都在这里处理,而viewWillAppear/viewDidAppear都无法正常工作.我还理解,在子视图或以编程方式创建的视图中,不会使用这些方法.但这在万一情况下不适用,我也想知道为什么要使用其中一种生命周期"方法,而另一种则不行.
However, while methods viewDidLoad and viewWillAppear are called, the method viewDidAppear is not called. Can anybody tell me why? Most questions I found on the web and here deal with both viewWillAppear/viewDidAppear are not working; I also understood that in subviews or programmatically created views these methods are not evoked; but this does not apply in case and also I wonder why one of these "lifecycle" methods is evoked and the other not.
有什么主意吗?谢谢!
推荐答案
我遇到了这个问题:viewWillAppear
被调用,但viewDidAppear
没有!
I had this issue happen to me: viewWillAppear
was being called but viewDidAppear
was not!
我终于发现这是因为我有一个tabBarController
,其中我自己重载了viewDidAppear
而忘记了[super viewDidAppear:animated];
I finally figured out that this was because I had a tabBarController
where I overloaded it's own viewDidAppear
and forgot the [super viewDidAppear:animated];
它在每个选项卡中的每个VC
都抛出了!重新添加该行以修复我的其他VC's
.
It threw off every VC
in every tab! adding that line back in fixed it for my other VC's
.
希望这对某人有帮助!
这篇关于UIViewController:调用viewWillAppear,不调用viewDidAppear的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!