I have a couple of custom NSBox subclasses called OuterBox and InnerBox. I've set up my view in a XIB and arranged the hierarchy like this:
OuterBox : NSBox
NSButton
NSBox
InnerBox : NSBox
...and some other views
The idea is that when the NSButton gets pressed, in an IBAction method, I want to get the superview of the button and then, from that, get the InnerBox that is in the same OuterBox as the button.
To do this, I loop through the OuterBox's subviews and check their type:
for (NSObject *subview in [outerBox subviews]) {
// this never evaluates to true...
if ([subview isKindOfClass:[InnerBox class]]) {
// ...
}
}
The problem is that my if
statement never hits. subview
shows up in the debugger as an NSView. According to the documentation, isKindOfClass:
returns
YES
if the receiver is an instance of aClass or an instance of any class that inherits from aClass, otherwiseNO
.
I understand why it's returning NO
: because InnerBox is a type of NSView but not vice versa. But I don't know why subview
is a UIView when it should be an InnerBox.
I have imported InnerBox.h and made sure that the InnerBox really is an InnerBox in the XIB. I don't know what could be causing its type to get changed, or be reported incorrectly...