内容简介:翻译自:https://stackoverflow.com/questions/10910306/how-to-implement-addtarget-property-in-a-uibutton
我有一个函数(例如function1),我有一个按钮和一个名为auxiliarStruct的对象,我有这条线:
[btn addTarget:self action:@selector(userSelected:) forControlEvents:UIControlEventTouchUpInside];
但是在@selector(userSelected)中我需要将该函数中所需的对象作为参数传递,但我不知道如何实现它.
我在这里声明了这个对象:
//UsersController.h
#import <UIKit/UIKit.h>
@interface UsersController : NSObject{
NSInteger *prof_id;
NSString *createTime;
NSString *fullName;
NSString *thumb;
}
@property (nonatomic) NSInteger *prof_id;
@property (nonatomic, retain) IBOutlet NSString *createTime;
@property (nonatomic, retain) IBOutlet NSString *fullName;
@property (nonatomic, retain) IBOutlet NSString *thumb;
@end
我有这样声明的被调用函数:
-(void)userSelected:(id)sender{
//CODE
}
我有一个这个类的对象,叫做auxiliarStruct,这就是我需要的.我试过了
[btn addTarget:self action:@selector(**userSelected:auxiliarStruct**)forControlEvents:UIControlEventTouchUpInside];
但它不起作用
谁能帮我?谢谢.
ps:对不起我的英语,我知道这很糟糕
您只能使用addTarget @selector方法将(UIButton *)对象作为参数传递.您可以设置UIButton标记并在被调用函数上使用它.您可能想要找出发送字符串值的任何替代方法.
使用以下代码通过按钮传递标记:
btn_.tag = 10;
[btn_ addTarget:self action:@selector(functionName:) forControlEvents:UIControlEventTouchUpInside];
按钮操作应如下所示:
- (void) functionName:(UIButton *) sender {
NSLog(@"Tag : %d", sender.tag);
}
翻译自:https://stackoverflow.com/questions/10910306/how-to-implement-addtarget-property-in-a-uibutton
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
现代体系结构的优化编译器
[美] Randy Allen,( / 机械工业出版社 / 2004-1 / 69.00元
现代体系结构的优化编译器,ISBN:9787111141228,作者:(美)Randy Allen,(美)Ken Kennedy著;张兆庆等译;张兆庆译一起来看看 《现代体系结构的优化编译器》 这本书的介绍吧!