views:

64

answers:

1

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)];

...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.

A: 

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

Daniel
Thanks. Three months into full-time iPhone development, I'm still not exempt from rookie mistakes...
Dan Ray
three months isnt that long :)
Daniel