此图片http://postimg.org/image/3qo8x6lyv/
在AddContactViewController.m中(对于蓝色的)
-(void)viewWillDisappear:(BOOL)animated{
[self passBD];
}
- (void)passBD {
//some code
[self.delegate passDataBack:p];
}
passDataBack
在AddContactViewController.h中声明,并在MasterViewController.m(对于灰色的)和DetailViewController.m(对于yellow-ish)中定义。我对该计划进行了描述,但我发现:
当我从Master转到AddContact视图控制器时返回viewWillDisappear
,执行调用passBD
调用MasterViewController中定义的passDataBack
。
当我从Detail返回AddContact视图控制器时返回viewWillDisappear
执行调用passBD
但它不调用DetailViewController.m中定义的passDataBack
痕迹刚好过去了。当我命令+单击passDataBack
时,它会显示三个选项Master,Detail和Add。为什么从一个VC执行它而不是从另一个VC执行呢?
编辑 DetailViewController.m
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"editContact"]){
AddConatctViewController *passData = [segue destinationViewController];
//some code
}
}
MasterViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"addContact"]){
self.addContactVC = segue.destinationViewController;
self.addContactVC.delegate = self;
}
}
编辑2 的 AddContactViewController.h
#import <UIKit/UIKit.h>
#import "PersonHolder.h"
@protocol AddDataDelegate <NSObject>
@required
- (void) passDataBack:(PersonHolder *)data;
@end
@interface AddConatctViewController : UIViewController
@property (nonatomic,weak) id <AddDataDelegate> delegate;
@end