我们假设我们有两个班级
UIViewParent :UIView
UIViewChild : UIViewParent
以及UIViewParent.xib
如何加载UIViewChild
usig UIViewParent.xib
?
到目前为止,我试过了:
UIViewChild *view = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([UIViewParent class]) owner:self options:nil] firstObject];
但是我无法调用UIViewChild
方法,它被标识为UIViewParent
类。
@Edit
@interface UIViewParent : UIView
@end
@interface UIViewChild : UIViewParent
- (void)someChildMethod;
@end
@implementation UIViewChild
- (void)someChildMethod{}
@end
UIViewParent.xib
是UIViewParent class
现在ViewController中的某个地方我正在尝试:
//Here is question HOW to get view with Parent.xib
UIViewChild *view = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([UIViewParent class]) owner:nil options:nil] firstObject];
[view someChildMethod]; //Crash because view is identified as UIViewParent not UIViewChild
[self.stackView addArrangedSubview:view];
我不知道如何更简单地描述它。