當執行模式的segue時,在執行segue之後,原始ViewController是否被丟棄?我將目標控制器的委託設置爲源ViewController,但是當目標ViewController.viewDidLoad,self.delegate爲零時...iOS Modal Segue丟棄源ViewController?
以下代碼將生成日誌消息「ListViewController.viewDidLoad:我的委託爲零:(」
[來源]的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");
}
}
是否'MapViewController.prepareForSegue:Segue公司mapToList ...'顯示在控制檯? – Dion 2012-04-10 19:37:04
是的,對不起,覺得那樣會很明顯。經過一些測試,特別是更改爲push segue,似乎原來的ViewController確實被解僱/清除...... – wuntee 2012-04-10 20:07:44
我剛做了一個新的應用程序,它工作正常。 [在github上查看](https://github.com/mikezehrer/ModalDelegation)。 – 2012-04-10 20:54:04