IOS View传统的价值观之间
2015-09-24 09:38
375 查看
1、采用NSUserDefaults通过值,这样的方法不限于传送少量数据的:
比方你要传一个float的值。在须要传的时候用
[[NSUserDefaults standardUserDefaults] setFloat:float forKey::@"float"]
接收值的时候用
[[NSUserDefaults standardUserDefaults] floatForKey:@"float"]
2、NSNotificationCenter来传值
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
CGRect roundRect = [self rectNeedRefreshFromThisPoint:point];
mLastPoint = CGPointMake(-1, -1);
NSLog(@"%s: point(%f,%f)", __FUNCTION__, point.x, point.y);
[self addToCurrentLineWithPoint:point.x y:point.y];
[self endLine];
[self setNeedsDisplayInRect:roundRect];
NSNumber *pointX = [NSNumber numberWithFloat:point.x];
NSNumber *pointY = [NSNumber numberWithFloat:point.y];
NSDictionary *pointDict = [NSDictionary dictionaryWithObjectsAndKeys:pointX,@"pointX",pointY,@"pointY", nil];
[[NSNotificationCenter defaultCenter]postNotificationName:@"passTouchedEndPointMsg"object:self userInfo:pointDict];
}
在消息中心的函数:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getTouchedPoint:)
name:@"passTouchedEndPointMsg"
object:nil];
- (void) getTouchedPoint:(NSNotification *)noti
{
NSDictionary *pointDict = [noti userInfo];
touchedEndPointX = [[pointDict objectForKey:@"pointX"] floatValue];
touchedEndPointY = [[pointDict objectForKey:@"pointY"] floatValue];
NSLog(@"%f:%f",touchedEndPointX,touchedEndPointY);
}
用消息来传參数有以下几点说法:object指的是发送者、在poseter端的userInfo里面能够存放要传的參数,必须为NSDictionary类型。在center端获取这个dictionary类型用:[notification userInfo];要得到
比方你要传一个float的值。在须要传的时候用
[[NSUserDefaults standardUserDefaults] setFloat:float forKey::@"float"]
接收值的时候用
[[NSUserDefaults standardUserDefaults] floatForKey:@"float"]
2、NSNotificationCenter来传值
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
CGRect roundRect = [self rectNeedRefreshFromThisPoint:point];
mLastPoint = CGPointMake(-1, -1);
NSLog(@"%s: point(%f,%f)", __FUNCTION__, point.x, point.y);
[self addToCurrentLineWithPoint:point.x y:point.y];
[self endLine];
[self setNeedsDisplayInRect:roundRect];
NSNumber *pointX = [NSNumber numberWithFloat:point.x];
NSNumber *pointY = [NSNumber numberWithFloat:point.y];
NSDictionary *pointDict = [NSDictionary dictionaryWithObjectsAndKeys:pointX,@"pointX",pointY,@"pointY", nil];
[[NSNotificationCenter defaultCenter]postNotificationName:@"passTouchedEndPointMsg"object:self userInfo:pointDict];
}
在消息中心的函数:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getTouchedPoint:)
name:@"passTouchedEndPointMsg"
object:nil];
- (void) getTouchedPoint:(NSNotification *)noti
{
NSDictionary *pointDict = [noti userInfo];
touchedEndPointX = [[pointDict objectForKey:@"pointX"] floatValue];
touchedEndPointY = [[pointDict objectForKey:@"pointY"] floatValue];
NSLog(@"%f:%f",touchedEndPointX,touchedEndPointY);
}
用消息来传參数有以下几点说法:object指的是发送者、在poseter端的userInfo里面能够存放要传的參数,必须为NSDictionary类型。在center端获取这个dictionary类型用:[notification userInfo];要得到
相关文章推荐
- iOS开发笔记--iOS 学习资料整理
- IOS控件 Tableview 下拉刷新,加载数据
- IOS 设置应用图标
- iOS编程规范
- iOS开发官方文档汇总
- iOS presentViewController背景色透明
- iOS实现倒计时功能
- 提高iOS开发效率的方法和工具
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- 浅谈——适配所有IOS版本的反地理编码的代理转block封装
- IOS 小例子,输出一个图形的坐标,颜色,形状。
- IOS6屏幕旋转详解(自动旋转、手动旋转、兼容IOS6之前系统)
- iOS中使用正则表达式NSRegularExpression 来验证textfiled输入的内容
- iOS AutoLayout自动布局中级开发教程(2)-等宽等高等中心
- iOS开发- OAuth2.0认证和SSO授权
- iOS开发-数据加密算法AES
- iOS开发-调整按钮的图片文字位置
- iOS开发-Xcode6应用程序国际化本地化
- IOS版应用商店应用源码
- iOS经典讲解之线程锁NSLock案例(卖火车票)