Is there any seriously good reason why a view can not completely manage itself?

Posted by mystify on Stack Overflow See other posts from Stack Overflow or by mystify
Published on 2010-05-23T22:30:21Z Indexed on 2010/05/23 22:30 UTC
Read the original article Hit count: 184

Filed under:
|

Example: I have an warning triangle icon, which is a UIImageView subclass. That warning is blended in with an animation, pulses for 3 seconds and then fades out.

  • it always has a parent view!

  • it's always only used this way: alloc, init, add as subview, kick off animation, when done:remove from superview

So I want this:

[WarningIcon warningAtPosition:CGPointMake(50.0f, 100.0f) parentView:self];

BANG!

That's it. Call and forget.

The view adds itself as subview to the parent, then does it's animations. And when done, it cuts itself off from the branch with [self removeFromSupeview];.

Now some nerd a year ago told me: "Never cut yourself off from your own branch". In other words: A view should never ever remove itself from superview if it's no more referenced anywhere.

I want to get it, really. WHY? Think about this: The hard way, I would do actually the exact same thing. Create an instance and hang me in as delegate, kick off the animation, and when the warning icon is done animating, it calls me back "hey man i'm done, get rid of me!" - so my delegate method is called with an pointer to that instance, and I do the exact same thing: [thatWarningIcon removeFromSuperview]; - BANG.

Now I'd really love to know why this sucks. Life would be so easy.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about core-animation