【问题标题】:add an action on a button without ibaction在没有 ibaction 的按钮上添加操作
【发布时间】:2012-08-06 12:11:49
【问题描述】:

我正在处理 mapkit 视图,我在注释上添加了一个按钮,如下所示:

UIButton *bt = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[bt setFrame:CGRectMake(0, 0, 30, 30)];

annView.rightCalloutAccessoryView = bt;

我想在触摸该按钮时转到另一个视图(例如 expleViewController),我习惯于使用 IBAction 方法并使用 Interface Builder 将其与按钮链接,但是此按钮是手动创建的,所以如何可以链接吗?

【问题讨论】:

  • 但是下次请努力阅读官方文档。

标签: objective-c ios cocoa-touch uibutton


【解决方案1】:
[bt addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

- (void)buttonPressed:(UIButton *)b
{
    // do whatever you want ;)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多