in my app i call a UIView and that UIView is like a settings screen in my app and i have buttons in the UIView and my question is how do i add actions to the buttons iv added to the UIViews subview? thanks,
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you’re writing code in a view controller for your settings UIView, the UIView is properly bound to the
viewproperty of your controller, and you have referenced one of the buttons with a variablebutton, here is what you would write:Another way to write that method is passing in a pointer to the button which was actually pressed, like so:
Rather than calling
addTarget:action:forControlEvents:, though, in Interface Builder (you should be doing this) after defining thebuttonPressedorbuttonPressed:method above, in the.xibfile with the button go to the second tab in the Inspector after clicking on the Button (it should say Button Connections), and click-drag the Touch Up Inside event to File’s Owner, and select “buttonPressed” from the list.