presentModalViewController viewDidLoad 没有被调用

发布于 2024-08-15 20:40:03 字数 545 浏览 8 评论 0原文

我有一个调用视图出现的事件,但 -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 技术交流群。

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

发布评论

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

评论(2

暮年慕年 2024-08-22 20:40:03

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:.

网名女生简单气质 2024-08-22 20:40:03

确保在每个方法中调用超类,例如

- (void)viewWillAppear:(BOOL)animated {
  NSLog(@"view appeared");
  [super viewWillAppear:animated];
}

Make sure you call the superclass in each of those methods, e.g.

- (void)viewWillAppear:(BOOL)animated {
  NSLog(@"view appeared");
  [super viewWillAppear:animated];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文