在进行模态转场时,执行转场后原始 ViewController 是否会被丢弃?我将目标控制器的委托设置为源 ViewController,但是当目标 ViewController.viewDidLoad 时,self.delegate 为 nil ...
以下代码将产生日志消息“ListViewController.viewDidLoad: My delegate is nil :(”
[来源] MapViewController:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"mapToList"]){
NSLog(@"MapViewController.prepareForSegue: Segue mapToList being called, setting LisViewController's delegate to myself");
[segue.destinationViewController setDelegate:self];
if(!self){
NSLog(@"MapViewController.prepareForSegue: I am nil.");
} else {
NSLog(@"MapViewController.prepareForSegue: I am NOT nil.");
}
}
}
[目的地] ListViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
if(!self.delegate){
NSLog(@"ListViewController.viewDidLoad: My delegate is nil :(");
} else {
NSLog(@"ListViewController.viewDidLoad: My delegate populated");
}
}