- 浏览: 887989 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (466)
- iPhone, iOS , Objective-c (155)
- 数据库 (20)
- 设计模式 (5)
- 第三方包管理,cocoapod (2)
- 版本管理, SVN, Subversion, Git (1)
- Google, Android, Java (14)
- Wordpress (1)
- 职业素养 (3)
- 版本管理,git (3)
- 前端小技巧 (2)
- flash (1)
- javascript (5)
- Ruby (0)
- 编程语言 (1)
- 网络常识 (1)
- 找到生活好感觉 (5)
- 产品经理 (1)
- markdown (1)
- 云服务器 (1)
- iPhone (116)
- iOS (116)
- Objective-c (116)
- 学习技巧 (2)
- Google (5)
- Android (6)
- Java (21)
- python (1)
- sqlite (3)
- node.js (2)
- mongodb (2)
- 学习技巧,阅读 (2)
- 软件测试 (3)
- 架构设计 (2)
- 设计 (1)
- Spring framework (3)
- junit (1)
- Linux (2)
- 软件 (1)
- Struts2 (1)
- 版本管理 (3)
- SVN (3)
- Subversion (3)
- Git (3)
- mysql (5)
- quartz (1)
- 无关技术 (1)
- 前端 (1)
- Redis (1)
- 产品管理 (0)
- 计算机常识 (1)
- 计算机科学 (0)
- swift (1)
- 服务器 (2)
- 搜索 (1)
- Scala (1)
- J2EE (1)
- maven (1)
- 前端css (1)
- 英语 (1)
- 消息队列 (1)
- kafka (0)
- apache kafka (4)
- netbeans (1)
- IDE (2)
- 歌词 (1)
- 过滤器实现 (1)
- linux vim vi (1)
- jmeter (1)
- springcloud (1)
最新评论
-
hujingnemo:
不知道为什么打不开
CHM如何改编字体大小 -
weiboyuan:
求答案 weiboyuanios@163.com
iOS软件工程师面试题(高级) -
xueji5368:
这个现在已经广泛使用了嘛!
RoboGuice入门 -
Yao__Shun__Yu:
...
CHM如何改编字体大小 -
353144886:
非常之详细 美女求认识
sqlite数据类型 datetime处理
I just ran into this problem and solved it. For ARC, the solution is to use the weak attribute instead of assign.
The crash come because the delegate
Has an assign attribute, AND
Has been deallocated.
Thus when you attempt to call the respondsToSelector method on delegate, you get a EXC_BAD_ACCESS. This is because objects that use the assign property will not be set to nil when they are deallocated. (Hence why doing a !self.delegate before the respondsToSelector does not prevent the responseToSelector from being called on a deallocated object, and still crashes your code)
The solution is to use the weak attribute, because when the object deallocates, the pointer WILL be set the nil . So when your code calls respondsToSelector on a nil, Objective C will ignore the call, and not crash.
As already mentioned, using a strong or assign attribute on a delegate (as many have mentioned) in ARC will result in a retain cycle. So don't do it, you don't need to.
assign “设置方法”只会招待针对“纯量类型”(scalar type,例如CGFloat或NSInteger等)的简单赋值操作。
strong 此特质表明该属性定义了一个拥有关系(owning relationship)。为这种属性设置新值时,设置方法会先保留新值,再释放旧值,然后再将新值设置上去。
weak 此特质表明该属性定义了一种非拥有关系(no owning relationship),为这种属性添加新值时,设置方法即不保留新值,也不保留旧值。此特质同assign类似,然而在改改所指的对象遭到摧毁时,属性值也会清空(nil out).
unsafe_unretained
看名字就知道了
不安全 不增加引用计数
NSString* str1 = @"123";
unsafe_unretianed NSString* str2 = str1;
[str1 release];
str2也跟着消失的无影无踪了,指针的地址空间都被清空了,和C++的引用很相似,别名
The crash come because the delegate
Has an assign attribute, AND
Has been deallocated.
Thus when you attempt to call the respondsToSelector method on delegate, you get a EXC_BAD_ACCESS. This is because objects that use the assign property will not be set to nil when they are deallocated. (Hence why doing a !self.delegate before the respondsToSelector does not prevent the responseToSelector from being called on a deallocated object, and still crashes your code)
The solution is to use the weak attribute, because when the object deallocates, the pointer WILL be set the nil . So when your code calls respondsToSelector on a nil, Objective C will ignore the call, and not crash.
As already mentioned, using a strong or assign attribute on a delegate (as many have mentioned) in ARC will result in a retain cycle. So don't do it, you don't need to.
assign “设置方法”只会招待针对“纯量类型”(scalar type,例如CGFloat或NSInteger等)的简单赋值操作。
strong 此特质表明该属性定义了一个拥有关系(owning relationship)。为这种属性设置新值时,设置方法会先保留新值,再释放旧值,然后再将新值设置上去。
weak 此特质表明该属性定义了一种非拥有关系(no owning relationship),为这种属性添加新值时,设置方法即不保留新值,也不保留旧值。此特质同assign类似,然而在改改所指的对象遭到摧毁时,属性值也会清空(nil out).
unsafe_unretained
看名字就知道了
不安全 不增加引用计数
NSString* str1 = @"123";
unsafe_unretianed NSString* str2 = str1;
[str1 release];
str2也跟着消失的无影无踪了,指针的地址空间都被清空了,和C++的引用很相似,别名
发表评论
-
oc为啥不用try catch
2016-03-23 11:56 1372简单的来说,Apple虽然同时提供了错误处理(NSError) ... -
ReactiveCocoa笔记
2016-03-14 12:31 0为什么使用MVVM?为什么使用ReactiveCocoa? 概 ... -
PINCache
2016-01-19 15:11 908PINCache是线程安全的键值缓存框架,用来储存难以获取或重 ... -
Swift设计模式
2015-12-29 12:04 0Swift设计模式 -
Understanding Swift access control
2015-12-29 12:03 0Swift takes an unusual approuac ... -
cocoapods因GEM_HOME升级遇到问题解决办法
2015-12-17 14:40 885Installing CocoaPods on OS X 10 ... -
swift 闭包的比较写法
2015-12-16 11:10 715let names = ["Chris", ... -
iOS 生成二维码,生成条形码图片
2015-12-03 15:44 1421#pragma mark - 生成条形码以及二维码 // ... -
解决cocoapods 更新慢的问题
2015-11-23 17:01 713最近使用CocoaPods来添加第三方类库,无论是执行pod ... -
iOS中级面试题
2015-11-20 15:12 1141OneV‘s Den在博客里出了10道iOS面试题,用他的话是 ... -
cocoapods出错解决方法
2015-11-09 13:09 707自定义GEM_HOME $ mkdir -p $HOME/So ... -
oc时间从美国时间改到中国时间
2015-10-19 14:12 925_formatter = [[NSDateFormatt ... -
27个iOS开发库
2015-07-24 16:10 738超长慎入列表: DZNEmptyDataSet(UI,空表格 ... -
Values of type 'NSInteger' should not be used as format arguments; add an explic
2015-07-24 10:10 802Values of type 'NSInteger' shou ... -
iOS架构心得体会
2015-05-18 18:35 773好的架构不是设计出来的,而是进行出来的。 我的iOS工程架构 ... -
UICollectionView NSInternalInconsistencyException出现的原因
2015-05-11 11:32 3367'NSInternalInconsistencyExcepti ... -
XLForm-iOS表单库
2015-05-08 14:44 876XLForm是最灵活和强大的iOS类库,用于创建动态table ... -
Info.plist Utility Error: “Info.plist couldn't be opened because there is no suc
2015-05-06 16:13 650http://stackoverflow.com/questi ... -
iOS中Autolayout中各种情况的使用的width,height策略
2015-04-30 15:33 643可以总结为: 如果项目不支持横屏显示,使用w:Compac ... -
一句话加上下拉刷新
2015-04-29 18:22 736怎么一句话添加上拉刷新? https://github.co ...
相关推荐
delegate与block的使用
delegate和block的使用
ios applicationDelegate使用;ios applicationDelegate使用
oc中以delegate实现页面间的传值过程
网上有很多关于C++ delegate机制的文章,但都讲的是函数指针的内容,上周就C++中实现C#的delegate机制的问题研究了好几天,查看了很多相关资料,才解决了问题,现将我写的C++ delegate测试程序贴出来,希望能帮到有...
本文实例讲述了C#使用委托(delegate)实现在两个form之间传递数据的方法。分享给大家供大家参考。具体分析如下: 关于Delegate【代理、委托】是C#中一个非常重要的概念,向前可以推演到C++的指针,向后可以延续到匿名...
支持为动态生成的标签元素绑定事件也许就live和delegate了吧,不过新版本已经不支持live了,只有delegate delegate真的比较特殊呀,不同于其他事件绑定的风格。 就因为习惯了之前的bind风格..栽了跟头 简单的说就是...
在qt的MVC模式中,运用控件在delegate中显示的方法。
delegate、五步曲、调用照相机、切换键盘
qt delegate代理的使用demo
一般在我们使用delegate都知道,是一对一的关系。在目前的项目中,有这样一个需求,在服务端收到了一个下发事件,需要在不同的页面,不同的VC都收到此事件,并进行相应的处理
(Swift)SceneDelegate中启动UI
对iOS的delegate代理方式不是很清楚的同学可以来看看,很简单的代码,看过之后应该给你有帮助
iOS 5 ARC完全指南中文 ...iOS 4 中使用ARC 27 ARC 高级指南 28 Blocks 与ARC 28 Singleton 与ARC 34 Autorelease 和AutoreleasePool 40 Cocos2D 和 Box2D 45 静态库static library 48 最后? 49 参考资料 49
本例子演示了iPhone开发中最常用到的两个类之间互相通信的方法之一:delegate
delegate_execute.exe
C# delegate thread范例 若不懂在代码中,线程如何调用的可以看看
C# Delegate讲解C# Delegate讲解C# Delegate讲解C# Delegate讲解
CSharp_Delegate C#委托 本人博客中的示例代码
网上也有很多Delegate的Demo,比较乱,感觉不容易看懂。本来一个很简单的问题,大家搞得这么复杂。这个Demo就通俗易懂、简单、实用