【问题标题】:Using IBActions with UIButtons without IBOutlet在没有 IBOutlet 的情况下使用带有 UIButtons 的 IBActions
【发布时间】:2011-11-30 06:55:04
【问题描述】:

抱歉标题不清楚。我希望能够将 IBAction 方法添加到我通过以下方式添加的按钮:

(.h 类)

{
    UIButton *button;
}
-(IBAction)ButtonReleased:(id)sender

(.m 类)

{
    -(IBAction)ButtonReleased:(id)sender
    {
        //Actions done by button pointer
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        [PlayButton setFrame:CGRectMake(10, 10, 100, 50)];
        [PlayButton setTitle:@"PlayButton" forState:UIControlStateNormal];
        [self.view addSubview:PlayButton];
    }
}

问题是,如何将 UIButton 按钮操作(例如,TouchUpInside)连接到 ButtonReleased 方法。

【问题讨论】:

    标签: ios xcode cocoa-touch uibutton ibaction


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

    【讨论】:

      猜你喜欢
      • 2015-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-01
      • 2018-10-18
      • 2020-11-05
      • 2018-10-14
      相关资源
      最近更新 更多