【发布时间】:2011-03-23 03:55:43
【问题描述】:
第一次在这里提问。
我有一个问题,我有一个UIImageView 作为子视图添加到我的UIButton,它是使用buttonWithType: 声明的(这意味着我不必释放按钮吗?)但我仍然必须释放我的UIButton 的子视图吗?
代码位:
UIImage *circleImage = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"item-circle" ofType: @"png"]];
UIImageView *circleImageView = [[[UIImageView alloc] initWithImage: circleImage] autorelease];
[imageView setFrame: CGRectMake(-5, -5, 65, 65)];
UIButton *button = [UIButton buttonWithType: UIButtonTypeCustom];
[button addSubview: circleImageView];
【问题讨论】:
-
欢迎来到 StackOverflow!请记住将答案标记为正确,并注意提问的方式。
-
谢谢 :) 糟糕,我注意到我已经自动释放了 UIImageView,所以这样可以吗?
-
你的代码很好,
circleImageView将被button保留,直到按钮被释放,但你不必担心它,因为你分配的唯一对象已被标记为无论如何自动释放。
标签: objective-c uibutton release subview autorelease