开发者

Adding subview then releasing it: "modifying view that is being finalized"

I've got a UIButton called tagButton and a UIScrollView called tagsView.

Inside my -(void)renderTags method, I do

[[self.tagsView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
开发者_JS百科

...to clear the decks, then I walk through a pair of arrays called allTags and activeTags, alternately creating "lit" and "unlit" buttons for each tag the user has ever used in the app. So far so good. But when I add the newly created UIButton to my view, thusly:

[self.tagsView addSubview:tagButton];
[tagButton release];

...the first time, nothing happens on the view, the tag button doesn't show up. The second time I put that same string in (which fires -toggleTag rather than -createTag, but ends up in the same rendering method), I get the console message modifying layer that is being finalized = 0x82b3ec0.

If I comment out [tagButton release], though, everything works. So, what gives? I thought adding a subview to a superview made the superview retain it. I'm not going to deal with this button again except to tell it to remove itself next time I render my tag list, so it seems like the view controller ought to release it.


Your problem is probably that you arent retaining tagButton to begin with, therefore there is no need to release it...hope that helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜