为什么Apple以这种方式创建它的视图 [英] Why does Apple create its views this way

查看:89
本文介绍了为什么Apple以这种方式创建它的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望修复我的另一个帖子的错误我想知道为什么苹果写这个(为它的元素示例)

In the hope of fixing a bug of mine from another post i would like to know why apple writes this (for it's Elements example)

UIView *localContainerView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.containerView = localContainerView;
[localContainerView release];

而不是更简单的方法:

containerView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

推荐答案

self.containerView = 实际上是 [self setContainerView:] 之前分配新值。当你直接赋值时,你必须知道该成员没有引用任何东西,例如因为你刚刚释放它或检查一个 nil 值。

self.containerView = is actually [self setContainerView:], which will usually release any previous value before assigning a new value. When you assign directly, you have to know that the member was not holding a reference to anything, for example because you just released it or checked for a nil value.

[self setContainerView:] 还可以处理任何其他处理。

[self setContainerView:] can also handle any additional processing.

这篇关于为什么Apple以这种方式创建它的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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