0

So I was adding labels and such to my UITableViewCell and when I added the subviews, I learned I needed to remove them or else they would remain glitchy...

I can understand that, but now when I am using a custom cell class, I no longer have to remove the added subviews. Why is this?

I simply initialized the label in the my custom cell class's init method, with a custom frame (not through IB).

4

1 回答 1

0

我怀疑你留下了一个额外的参考。请注意,[[foo alloc] init] 返回一个带有 +1 的 ref,添加子视图会增加一个 ref。

使用 addsubview 的正常方法是像这样传递它自动释放的引用(示例)。

[cell addSubview:[UILabel label:args]];

或者这个(例子):

[cell addSubview:[[[Foo alloc] init] autorelease]];
于 2013-01-12T22:31:19.117 回答