iPhone:为什么我需要自我.在viewDidUnload中? [英] iPhone: Why do I need self.<> in viewDidUnload?

查看:46
本文介绍了iPhone:为什么我需要自我.在viewDidUnload中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从别人那里听说您应该在viewDidUnload中使用self.例如,这很好:

I heard from people that you should use self in viewDidUnload. For instance, this is good:

- (void)viewDidUnload
{
   self.object = nil;
   self.object2 = nil
}


- (void)viewDidUnload
{ 
    object = nil;
    object2 = nil;
}

两者之间有区别吗?那是什么?

Is there a difference between the 2? And what is it?

推荐答案

有区别.@synthesize生成的代码将在设置新值之前调用对您所拥有的对象的引用上的release.对self.object = nil的调用将有效地释放引用并将其设置为nil.如果没有自我,它将只是将引用设置为nil.

There is a difference. The code that is generated by @synthesize will call release on the references to the objects you have before setting the new value. A call to self.object = nil will effectively both release the reference and set it to nil. Without the self it will just set the reference to nil.

这篇关于iPhone:为什么我需要自我.在viewDidUnload中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆