I want to pass a variable to a UIButton action, for example
NSString *string=@\"one\";
[downbutton addTarget:self action:@selector(action1:string)
forCo
Another option for passing variables, which I find to be more direct than the tag from leviatan's answer is to pass a string in the accessibilityHint. For example:
button.accessibilityHint = [user objectId];
Then in the action method of the button:
-(void) someAction:(id) sender {
UIButton *temp = (UIButton*) sender;
NSString *variable = temp.accessibilityHint;
// anything you want to do with this variable
}
You can extends UIButton and add a custom property
//UIButtonDictionary.h
#import <UIKit/UIKit.h>
@interface UIButtonDictionary : UIButton
@property(nonatomic, strong) NSMutableDictionary* attributes;
@end
//UIButtonDictionary.m
#import "UIButtonDictionary.h"
@implementation UIButtonDictionary
@synthesize attributes;
@end