在界面生成器中设置按钮但想调用自定义 init 方法
Setting up buttons in interface builder but want to call custom init method
我有一个自定义 UIButton class。我已经在界面生成器中设置了按钮。我有这个代码:
#import "FriendButton.h"
@implementation FriendButton
-(id)init {
self = [super init];
NSLog(@"init called");
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
[self addGestureRecognizer:longPress];
return self;
}
虽然它没有被调用,但我已经在界面生成器中将 class 类型设置为 FriendButton。我需要使用其他方法吗?我知道对于自定义 UITableViewCell
s 必须使用 awakeFromNib
.
来自 Apple 文档:
Objects that conform to the NSCoding protocol (including all
subclasses of UIView and UIViewController) are initialized using their
initWithCoder: method.
我有一个自定义 UIButton class。我已经在界面生成器中设置了按钮。我有这个代码:
#import "FriendButton.h"
@implementation FriendButton
-(id)init {
self = [super init];
NSLog(@"init called");
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
[self addGestureRecognizer:longPress];
return self;
}
虽然它没有被调用,但我已经在界面生成器中将 class 类型设置为 FriendButton。我需要使用其他方法吗?我知道对于自定义 UITableViewCell
s 必须使用 awakeFromNib
.
来自 Apple 文档:
Objects that conform to the NSCoding protocol (including all subclasses of UIView and UIViewController) are initialized using their initWithCoder: method.