Swa*_*nil 1 iphone objective-c
我正在尝试以下任务:
我知道我们可以通过使用按钮点击calla方法:
[button addTarget:self action:@selector(performModalActionForButton)
forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)
方法如下:
(void) performModalActionForButton:(NSString *)str
{
}
Run Code Online (Sandbox Code Playgroud)
我想在按钮单击上发送一个字符串到一个方法.我怎样才能做到这一点?
谢谢
您的代码中有两个小错误..
如果您使用@selector并想要选择带参数的函数,您可以添加:...所以它是@selector(performModalActionForButton:)
传递给函数的对象总是消息的发送者..所以函数将是:
- (void) performModalActionForButton:(UIButton *)button
{
}
Run Code Online (Sandbox Code Playgroud)在该功能中,您可以检查按钮上的文本然后...或标签或任何您想要的内容.