开发者

Using IBActions with UIButtons without IBOutlet

开发者 https://www.devze.com 2023-04-10 16:05 出处:网络
Sorry for the unclear title. I want to be able to add IBAction methods to a button I added in the following way:

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

精彩评论

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