iOS开发之观察者
2016-05-26 13:35
357 查看
//观察者事件 (!!注册必删除)
[[IndexViewInformation
sharedInstance]
addObserver:self
forKeyPath:@"selectedMoreModel"
options:NSKeyValueObservingOptionNew |
NSKeyValueObservingOptionOld
context:nil];
[[IndexViewInformation
sharedInstance]
addObserver:self
forKeyPath:@"selectedBuyModel"
options:NSKeyValueObservingOptionNew |
NSKeyValueObservingOptionOld
context:nil];
//删除注册的观察者事件
[[IndexViewInformation
sharedInstance]
removeObserver:self
forKeyPath:@"selectedBuyModel"];
[[IndexViewInformation
sharedInstance]
removeObserver:self
forKeyPath:@"selectedMoreModel"];
//观察者触发的事件,在观察者观察到变化的时候触发
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary
*)change context:(void *)context {
if ([keyPath
isEqualToString:@"selectedMoreModel"]) {
UIStoryboard *board=[UIStoryboard
storyboardWithName:@"Main"
bundle:nil];
ProjectDetailViewController *pro =[board
instantiateViewControllerWithIdentifier:@"ProjectDetail"];
pro.shengyuTime = [IndexViewInformation
sharedInstance].selectedMoreModel.thenDays;
pro.projectID = [IndexViewInformation
sharedInstance].selectedMoreModel.prodectId;
pro.thenDays = pro.shengyuTime;
[self.navigationController
pushViewController:pro
animated:YES];
NSLog(@"触发MoreModel观察者~!");
}
if ([keyPath
isEqualToString:@"selectedBuyModel"]) {
NSLog(@"触发BuyModel观察者~!");
[self
requestBeforeBuy];
}
}
再次强调,观察者添加必有删除,如果忘记删除,会导致意想不到的麻烦。
本文有因为问题请联系
QQ:563699115
Telephone:18341266547
[[IndexViewInformation
sharedInstance]
addObserver:self
forKeyPath:@"selectedMoreModel"
options:NSKeyValueObservingOptionNew |
NSKeyValueObservingOptionOld
context:nil];
[[IndexViewInformation
sharedInstance]
addObserver:self
forKeyPath:@"selectedBuyModel"
options:NSKeyValueObservingOptionNew |
NSKeyValueObservingOptionOld
context:nil];
//删除注册的观察者事件
[[IndexViewInformation
sharedInstance]
removeObserver:self
forKeyPath:@"selectedBuyModel"];
[[IndexViewInformation
sharedInstance]
removeObserver:self
forKeyPath:@"selectedMoreModel"];
//观察者触发的事件,在观察者观察到变化的时候触发
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary
*)change context:(void *)context {
if ([keyPath
isEqualToString:@"selectedMoreModel"]) {
UIStoryboard *board=[UIStoryboard
storyboardWithName:@"Main"
bundle:nil];
ProjectDetailViewController *pro =[board
instantiateViewControllerWithIdentifier:@"ProjectDetail"];
pro.shengyuTime = [IndexViewInformation
sharedInstance].selectedMoreModel.thenDays;
pro.projectID = [IndexViewInformation
sharedInstance].selectedMoreModel.prodectId;
pro.thenDays = pro.shengyuTime;
[self.navigationController
pushViewController:pro
animated:YES];
NSLog(@"触发MoreModel观察者~!");
}
if ([keyPath
isEqualToString:@"selectedBuyModel"]) {
NSLog(@"触发BuyModel观察者~!");
[self
requestBeforeBuy];
}
}
再次强调,观察者添加必有删除,如果忘记删除,会导致意想不到的麻烦。
本文有因为问题请联系
QQ:563699115
Telephone:18341266547
相关文章推荐
- iOS开发之通知中心
- iOS开发之Xcode优化,清理Xcode编译缓存,清除provisioning profile 证书,添加provisioning profile证书
- iOS开发之NSUserDefault详解
- iOS开发之AFNetworking上传
- ios,关于bounds,frame,修改bounds…
- iOS动态绘制曲线
- iOS开发之详解正则表达式
- iOS导航栏的按钮处理
- iOS开发之渐变色的实现
- iOS中删掉字符串中的空白格
- IOS中KVO模式的解析与应用
- iOS开发 : Navigation Bar的简单设置
- iOS 最新版 CocoaPods 的安装/使用流程
- iOS开发~设置label上文字显示不同大小、颜色、字体类型
- IOS照片颠倒分析及移动/页面端的处理策略和思路
- iOS开发之手势解锁详解
- iOS CoreAnimation 关键帧动画 CAKeyframeAnimation
- iOS开发之深复制浅复制
- iOS推送的众多坑
- iOS-本地通知