I was wondering if it was possible to extend classes, e.g. UIView or UITextView with categories and have the extension picked up by Interface Builder?
Let's assume we want to add a previous and next outlet to each UITextView, ideally one would write the category to extend the UITextView and have Interface Builder pick that change up. Consequently offer开发者_如何学运维ing previous and next outlets on all UITextViews.
But that attempt seems to fail. Is it still possible?
Outlets are ivars. You can't add ivars in a category.
But what you can do is write a subclass of UITextView (maybe call it SequenceTextView or something). Add whatever outlets you desire as properties/ivars of the subclass. Then add a UITextView in IB and set its class to SequenceTextView and your outlets should appear. Just remember always to use SequenceTextView instead of UITextView when you need those outlets.
Bonus hint: for easy access later, drag SequenceTextView from your .xib window into the Custom Objects section of IB's Library panel. That will save you the trouble of setting the class identity (and other default parameters) by hand every time.
Outlets are not ivars, they are properties, they could resolve to an existing ivar for example. I think category support would be useful but is unfortunately not supported.
精彩评论