Can I make a UIControl take ownership of "disposable" event targets?
In my view controller I'm programmatically creating N buttons in my UIView
. Each button needs to do something different, so I've made a custom handler class, which I create N instances of, each initialized with custom data. I create开发者_开发技巧 them in the body of a for
loop and add them as targets, after which I don't need them anymore.
However, because UIControl
s don't take ownership of their event targets, I need to hang on to these custom handlers myself (in the controller), introducing an extra ivar and the necessary release code. Is there a more elegant way to handle this problem?
Add those custom handlers to an NSArray that you retain in your controller (whatever controller is creating the buttons). Adding an object to an array retains it, so you will know that it is always around.
Associative references?
精彩评论