IOS: one IBAction for multiple buttons

2019-01-11 02:39发布

In my project I must control action of 40 buttons, but I don't want to create 40 IBAction, can I use only a IBAction, how?

7条回答
冷血范
2楼-- · 2019-01-11 03:31
-(IBAction)myButtonAction:(id)sender {
    if ([sender tag] == 0) {
        // do something here
    }
    if ([sender tag] == 1) {
        // Do something here
    }    
}

// in Other words

-(IBAction)myButtonAction:(id)sender {
        switch ([sender tag]) {
        case 0:
            // Do something here
            break;
        case 1:
           // Do something here
             break;
       default:
           NSLog(@"Default Message here");
            break;
}
查看更多
登录 后发表回答