NSNotificationCenter
注册通知:
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(myFun:) name:@" lisName" object:nil];
addObserver: 观察者,即在什么地方接收通知;
selector: 收到通知后调用何种方法;
name: 通知的名字,也是通知的唯一标示,编译器就通过这个找到通知的。
- (void) myFun:(NSNotification*) notification
{
id myobj = [notification object];//获取到传递的对象
}
发送通知:调用观察者处的方法。
[[NSNotificationCenter defaultCenter]postNotificationName:@"lisName" object:searchFriendArray];
postNotificationName:通知的名字,也是通知的唯一标示,编译器就通过这个找到通知的。
object:传递的参数
delegate
设置代理
myViewControl.delegate = self;//MainController实现中
实现代理
<myDelegate>//MainController原型中
实现代理方法
-(void)delegateFun:(id)sender//声明及调用
调用代理方法
[delegate delegateFunZ:self];