整理一下代理和通知中心的 基本用法。
1,代理,通常用于 有关联的页面之间赋值操作,像PUSH 父与子界面。
A 父视图 。
#import "B 子视图.h"
<mydelegate>
B 子视图。
@protocol mydelegate <NSObject>
-(void)gaibianyan ; //A 中的方法
@end
@property(strong,nonatomic)id<mydelegate> delegate;
在B子视图中不需要去 import A。
2 通知中心
//通知中心注册
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tongzhizhongxin:) name:@"tongzhizhongxin" object:nil];
-(void)tongzhizhongxin:(NSNotification*)notification
{
NSLog(@"收到通知");
if ([notification.object isEqualToString:@"1"]) {
NSLog(@"1");
}
else
{
NSLog(@"2");
}
//发送通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"tongzhizhongxin" object:@"1"];
}