【问题标题】:Setting up buttons in interface builder but want to call custom init method在界面生成器中设置按钮但想调用自定义初始化方法
【发布时间】:2015-02-18 16:49:57
【问题描述】:

我有一个自定义 UIButton 类。我已经在界面生成器中设置了按钮。我有这个代码:

#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;

}

虽然它没有被调用,但我已在界面构建器中将类类型设置为 FriendButton。我需要使用其他方法吗?我知道对于自定义UITableViewCells,必须使用awakeFromNib

【问题讨论】:

标签: objective-c xcode uibutton


【解决方案1】:

来自 Apple 文档:

符合 NSCoding 协议的对象(包括所有 UIView 和 UIViewController 的子类)使用它们的初始化 initWithCoder:方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-30
    • 2016-05-20
    • 1970-01-01
    • 2020-09-26
    • 2014-12-29
    • 1970-01-01
    相关资源
    最近更新 更多