问题
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