开发者

Using IBActions with UIButtons without IBOutlet

Sorry for the unclear title. I want to be able to add IBAction methods to a button I added in the following way:

(.h class)

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

(.m class)

{
    -(IBAction)ButtonRel开发者_如何转开发eased:(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];
    }
}

The question is, how can I connect the UIButton button action (say, TouchUpInside) to the ButtonReleased method.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜