viewWillAppear not called

我只是一个虾纸丫 提交于 2021-01-29 06:50:50

问题


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 animated:YES];

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

- (void)viewDidLoad {
[super viewDidLoad];

NSLog(@"test");
}

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


回答1:


Andreas,

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.



来源:https://stackoverflow.com/questions/4673294/viewwillappear-not-called

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!