UILabel字符串释放?
我有一个像这样的 IBAction:
-(IBAction)
{
[kolikoZvanja setText: [NSString stringWithFormat: @"%i + ", [Data variables].zvanja]];
}
其中 [Data Variables].zvanja
通过程序更改,因此 UILabel
也通过程序更改,我需要 release
每次都kolikoZvanja
?
I have an IBAction like this:
-(IBAction)
{
[kolikoZvanja setText: [NSString stringWithFormat: @"%i + ", [Data variables].zvanja]];
}
where [Data variables].zvanja
changes through program, so UILabel
changes too through program, do I need to release
kolikoZvanja
each time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你需要释放那些你保留的东西。您可以通过调用包括
new
、alloc
、copy
或retain
在内的方法来保留内容。您没有在此方法中的任何位置调用
retain
,因此没有理由调用release
。You need to release those things which you retain. You retain things by calling a method including
new
,alloc
,copy
orretain
.You aren't calling
retain
anywhere in this method, so there is no reason you should callrelease
.不,当然不是。如果每次释放标签,您将无法再设置其文本,或者每次都重新分配/初始化它并将其重新添加到视图中。
标签显示的字符串是由它复制的,所以它负责释放它。
No, of course not. If you release the label each time, you won't be able to set its text anymore, or you re alloc/init it each time and re-add it to the view.
The string displayed by the label is copied by it, so it is responsible for releasing it.
kolikoZvanja
是一个指向UILabel
的指针的属性。由于您仅设置此UILabel
的text
属性,因此您无法释放kolikoZvanja
,它是UILabel 的“访问门”
。释放kolikoZvanja
会导致丢失指向UILabel
的指针,因此您将无法设置它的text
属性。kolikoZvanja
is a property that is a pointer to aUILabel
. Because you are setting only thetext
property of thisUILabel
you cannot release thekolikoZvanja
which is your "access gate" for yourUILabel
. Releasing thekolikoZvanja
would effect in loosing a pointer to yourUILabel
hence you would not be able to set it'stext
property.