Alex Rivera | Logout

how to implement addTarget property in a UIButton

Asked 2012-06-06T08:00:07.837
8

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

Edit
Report

1 Answer

1

The event will send the button as parameter, so:

   -(void)userSelected:(id)sender {

           UIButton *button = sender;
           ...
    }
answered 2012-06-06T08:14:33.353

Your Answer