通知
//发送通知(用在需要传值的地方,比如把一个"对象"的值传到另一个界面)
[[NSNotificationCenter defaultCenter] postNotificationName:@"noticeNSNotification" object:对象];
//添加观察者(就是用在接受通知的界面,一般写在初始化方法中)
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(returnVcardType:) name:@"noticeNSNotification" object:nil];
//如下使用
- (void)dealloc{//通知使用完必须要移除
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"noticeNSNotification" object:nil];
}
- (instancetype)init{
if (self=[super init]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notice:) name:@"noticeNSNotification" object:nil];
}
return self;
}
//
- (void)notice:(NSNotification *)noti{
if (no.object) {
//no.object就是这个对象的值
//一般都是在这里给自定义的对象赋值,在viewWillAppear里使用自定义对象
}
}