presentModalViewController viewDidLoad 没有被调用
我有一个调用视图出现的事件,但 -viewdidload
事件每次调用时都没有按预期出现。这是我用来调用它的方法...
[self presentModalViewController:addItemViewController animated:YES];
然后在 addItemViewController 中,该方法是
- (void)viewDidLoad {
NSLog(@"alright, lad!");
}
要关闭视图,我有一个按钮,其代码为
- (IBAction)cancel {
[self dismissModalViewControllerAnimated:YES];
}
“好吧,小伙子”日志在视图第一次出现时显示,但再也不会显示当它推出时。有没有一种方法可以让应用程序“忘记”视图?或者我应该使用另一种加载方法?我尝试了 loadView (我认为),但屏幕空白...
感谢您的帮助!
I have an event which calls a view to appear, but the -viewdidload
event isn't appearing as expected each time it's called. Here's the method I use to call it...
[self presentModalViewController:addItemViewController animated:YES];
then inside the addItemViewController, the method is
- (void)viewDidLoad {
NSLog(@"alright, lad!");
}
To close the view, I have a button with the code
- (IBAction)cancel {
[self dismissModalViewControllerAnimated:YES];
}
the "alright, lad" log is shown the first time the view appears, but never again when it's launched. Is there a method I can use to let the app "forget" about the view? Or should I be using another load method? I tried loadView (I think) but that had a blank screen...
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
viewDidLoad仅在视图首次实例化时被调用。如果您不是每次都重新创建视图控制器,则只会调用它一次(如果收到内存警告并且视图为零,则再次调用)。您可能想使用 viewWillAppear: 或 viewDidAppear:。
viewDidLoad is only called when the view is first instantiated. If you're not recreating the view controller each time, you'll only get it called once (and called again if you get a memory warning, and the view is nil'd out). You probably want to use viewWillAppear: or viewDidAppear:.
确保在每个方法中调用超类,例如
Make sure you call the superclass in each of those methods, e.g.