How to connect multiple buttons in a storyboard to a single action?

后端 未结 7 1089
梦谈多话
梦谈多话 2020-12-03 10:16

I\'m currently using Xcode 4.6 and I\'m simply wondering how to select multiple buttons across different UIViews, but under a single view controller. CMD clicking doesn\'t s

7条回答
  •  没有蜡笔的小新
    2020-12-03 11:14

    Follow this steps

    1. Create IBAction In View Controller

    In .h file

    -(IBAction)action:(id)sender;
    

    In .m File

    -(IBAction)action:(id)sender{
    
    
    }
    

    2 . Connect all button to this action

    enter image description here

    3 . Give Each Button a tag by follow the next Picture enter image description here

    4 . Now inside your action function put these

        -(IBAction)action:(id)sender{
    
            UIButton *button=(UIButton*)sender;
    
            if(button.tag==1){
    
                //your stuff!
            }
            if(button.tag==2){
    
                //your stuff!
            }
            if(button.tag==3){
    
                //your stuff!
            }
    
        }
    

    Run and Go.

提交回复
热议问题