如何将变量传递给UIButton操作 [英] how to pass a variable to a UIButton action
本文介绍了如何将变量传递给UIButton操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将变量传递给UIButton操作,例如
I want to pass a variable to a UIButton action, for example
NSString *string=@"one";
[downbutton addTarget:self action:@selector(action1:string)
forControlEvents:UIControlEventTouchUpInside];
我的行动功能就像
-(void) action1:(NSString *)string{
}
但是,它会返回语法错误。
有人可以告诉我如何将变量传递给UIButton操作吗?
However, it returns a syntax error. Can someone show me how to pass a variable to a UIButton action?
推荐答案
将其更改为:
[downbutton addTarget:self action:@selector(action1:) forControlEvents:UIControlEventTouchUpInside];
我不知道Iphone SDK,但是按钮动作的目标可能会收到一个id (通常命名为发件人)。
I don't know about the Iphone SDK, but the target of a button action probably receives an id (usually named sender).
- (void) buttonPress:(id)sender;
在方法调用中,发件人应该是您案例中的按钮,允许您阅读诸如它的名字,标签等。
Within the method call, sender should be the button in your case, allowing you to read properties such as it's name, tag, etc.
这篇关于如何将变量传递给UIButton操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文