perfomSelector on按钮和发送参数 [英] perfomSelector on button and sending parameters
本文介绍了perfomSelector on按钮和发送参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含多个变量的方法:
I have a method with multiple variables:
-(void) showImg:(UIBarButtonItem *)sender string1:(NSString *) string2:(NSString *);
我想发送 NSString
值(As这个函数
用于多个元素)。
I want to send NSString
values (As this function
is used for multiple elements).
这是我在没有参数时添加动作
的方式:
This is how I add my action
when no parameters are needed:
[myButton addTarget:self action:@selector(showImg) forControlEvents: UIControlEventTouchUpInside];
我尝试在 @selector
中添加参数像这样:
I tried adding parameters within the @selector
like this:
[myButton performSelector @selector(showImg:string1:string2::) withObject:@"-1" withObject:@"-1"];
但这不起作用。如何在 @selector
中直接使用多个参数调用函数
?
But this does not work. How may I call my function
with multiple parameters directly inside the @selector
?
推荐答案
你可以让 UIButton
调用函数
在中间(像中间人),控制下一个函数参数。
You can make your UIButton
call a function
in between (like a middle man), to control the next functions parameters.
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[myButton addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
-(void) buttonTapped:(id)sender{
if(<some logical condition>){
[self showImg:sender string1:@"-1" string2:@"-1"];
}else {
[self showImg:sender string1:@"otherVal1" string2:@"otherVal2"];
}
}
-(void) showImg:(id)sender string1:(NSString *)string1 string2:(NSString*)string2 {
//Other logic
}
这篇关于perfomSelector on按钮和发送参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文