viewWillAppear没有被调用 [英] viewWillAppear not called

查看:48
本文介绍了viewWillAppear没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在显示模态对话框的视图控制器的视图中点击按钮时执行的代码:

This is the code that executes when a button is tapped in the view for the viewcontroller that displays the modal dialog:

-(IBAction)presentModally:(id)sender {  

if (self.nvc == nil) {
MyModalViewController *vc = [[MyModalViewController alloc] init];
UINavigationController *navvc = [[UINavigationController alloc] initWithRootViewController:vc];
navvc.navigationItem.prompt = @"";
navvc.navigationBar.barStyle = UIBarStyleBlack;
[vc release];
self.nvc = navvc;
[navvc release];
}
}

[self presentModalViewController:self.nvc动画:是];

[self presentModalViewController:self.nvc animated:YES];

如果每次显示视图时一切正常,则此代码应该启动.

This code should if everything was correct launch every time the view appear.

- (void)viewDidLoad {
[super viewDidLoad];

NSLog(@"test");
}

当我评论检查Ivar是否为零的if语句时,将调用viewWillAppear方法.有什么想法吗?

When I comment the if-statement that checks if the Ivar is nil the method viewWillAppear is invoked. Any ideas?

推荐答案

安德烈亚斯(Andreas)

Andreas,

不确定在这里是否混淆了viewDidLoad和viewWillAppear?您的viewDidLoad代码不会在每次显示视图时调用,仅在加载时会被调用.

not sure if you are confusing viewDidLoad and viewWillAppear here? Your viewDidLoad code will not get called every time the view appears, only on load.

此外,将导航控制器显示为模态视图对我来说似乎很奇怪-模态视图的要点是,当您让用户完成某些任务(例如发送电子邮件链接,然后他们将其关闭,然后返回原处.

Also, displaying a Navigation controller as a modal view seems a strange thing to do to me - the whole point of modal views is they prevent the user navigating away as you get them to complete some task, like sending an email link, then they dismiss it and go back to where they were.

这篇关于viewWillAppear没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆