故事板正在初始化 UIView 而不是我的自定义 class
Storyboard initializing UIView instead of my custom class
我有一个名为 NumberView
的自定义 class,它是 class 的 UIScrollView
。我将 UIView
放到故事板上,并将 class 更改为 NumberView
:
然后我为 ShotTraceViewController
class:
创建了一个出口
@interface ShotTraceViewController ()
@property (weak, nonatomic) IBOutlet NumberView *numberView;
@end
我在 NumberView.h
和 NumberView.m
:
中定义了一些方法
.h:
@interface NumberView : UIScrollView
@property (weak, nonatomic) id<NumberViewDelegate> number_delegate;
-(void)setTotalBtns:(int)total;
...
@end
.m:
@interface NumberView ()
@end
@implementation NumberView {
}
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
return self;
}
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
return self;
}
-(void)setTotalBtns:(int)total {
NSLog(@"Setting buttons");
}
@end
但是当我尝试从我的 ShotTraceViewController
调用 [self.numberView setTotalBtns:3];
时。我得到一个例外:
-[UIView setTotalBtns:]: unrecognized selector sent to instance 0x104fad3e0
哇!不对,应该是 NumberView
而不是 UIView
!我做错了什么吗?
我还注意到 initWithFrame 和 initWithCoder 都没有被调用。
我不知道为什么会这样,但取消选中 class 选择下方的 Inherit Module from Target
按钮可以解决所有问题。
我有一个名为 NumberView
的自定义 class,它是 class 的 UIScrollView
。我将 UIView
放到故事板上,并将 class 更改为 NumberView
:
然后我为 ShotTraceViewController
class:
@interface ShotTraceViewController ()
@property (weak, nonatomic) IBOutlet NumberView *numberView;
@end
我在 NumberView.h
和 NumberView.m
:
.h:
@interface NumberView : UIScrollView
@property (weak, nonatomic) id<NumberViewDelegate> number_delegate;
-(void)setTotalBtns:(int)total;
...
@end
.m:
@interface NumberView ()
@end
@implementation NumberView {
}
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
return self;
}
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
return self;
}
-(void)setTotalBtns:(int)total {
NSLog(@"Setting buttons");
}
@end
但是当我尝试从我的 ShotTraceViewController
调用 [self.numberView setTotalBtns:3];
时。我得到一个例外:
-[UIView setTotalBtns:]: unrecognized selector sent to instance 0x104fad3e0
哇!不对,应该是 NumberView
而不是 UIView
!我做错了什么吗?
我还注意到 initWithFrame 和 initWithCoder 都没有被调用。
我不知道为什么会这样,但取消选中 class 选择下方的 Inherit Module from Target
按钮可以解决所有问题。