在没有IBOutlet的情况下使用带有UIButton的IBActions

时间:2011-10-03 22:42:46

标签: ios xcode cocoa-touch uibutton ibaction

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

(。h class)

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

(.m class)

{
    -(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方法。

1 个答案:

答案 0 :(得分:5)

[button addTarget:self action:@selector(ButtonReleased:) forControlEvents:UIControlEventTouchUpInside];