I have a function (for example function1)where I have a button and an object called auxiliarStruct, and I have that line:
[btn addTarget:self action:@selector(userSelected:) forControlEvents:UIControlEventTouchUpInside];
But in @selector(userSelected) I need to pass as parameters an object needed in that function, but I don’t know how implement it.
I have declared that object here:
//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
I have the called function declared like this:
-(void)userSelected:(id)sender{
//CODE
}
I have an object of this class, called auxiliarStruct and this is that I need. I tried with
[btn addTarget:self action:@selector(**userSelected:auxiliarStruct**)forControlEvents:UIControlEventTouchUpInside];
but it don’t works
Can anyone help me? Thanks.
ps: sorry for my english, i know it’s bad
You can only Pass a
(UIButton*)object as a parameter withaddTarget @selectormethod. You can set the UIButton tag and use it on the called function. You may want to find out any alternatives for sending string values.Use the below code for passing a tag with button :
The button action should look like this :