The easiest way to bind βparametersβ to a rubimotion UIButton call is to use tags.
First configure the button with the tag attribute. This tag is the parameter that you want to pass to the target function.
@button = UIButton.buttonWithType(UIButtonTypeRoundedRect) @button.setTitle "MyButton", forState:UIControlStateNormal @button.frame =[[0,0],[100,50]] @button.tag = 1 @button.addTarget(self, action: "buttonClicked:", forControlEvents:UIControlEventTouchUpInside)
Now create a method that takes sender as a parameter:
def buttonClicked(sender) mytag = sender.tag
Warning. As far as I know, the tag attribute accepts only integer values. You can get around this by putting your logic in the target function as follows:
def buttonClicked(sender) mytag = sender.tag if mytag == 1 string = "Foo" else string = "Bar" end end
First, I tried to set the action with action: :buttonClicked , which worked, but did not allow the use of the sender method.
source share