I have extended NSScrollView to be non-flipped with a category (by default it is flipped). Then I added an NSScrollView to my application with Interface Builder. The NSScrollView is flipped.
How can this happen? I don’t include my category in any source file in my project. I only compile it in which seems to somehow be enough. And I did do a clean build, just to be safe.
And most importantly: How can I change this behavior? I don’t want my nibs to automatically pick up all categories they can find, on the other hand it could be handy to sometimes include them. But I’ve always seen categories as opt-in, not opt-out as this seems to be here.
Any idea?
Categories apply to the entire class; all instances of NSScrollView ANYWHERE in your program will pick up the new behavior. For this reason, it’s generally not a good idea to override existing methods in a category; you’re changing the behavior of that method for all users of the class, not just your own instances.
So categories are neither opt-in nor opt-out; they are absolute and overriding. If the category is compiled into the program, then every instance that class will be affected. They can neither opt in nor opt out; the new behavior is forcibly imposed upon them by the runtime. Keep that in mind when using categories.
If you want to change the behavior for some instances, then you should make a subclass of NSScrollView (call it UnflippedScrollView or something) and override the method there. Then use your subclass where you need an unflipped scroll view.