I want to pass a url through button action, because i have 10 buttons which are created through code dynamically and on clicking then there a specific url are assign for each corresponding button. Here is my code
NSString *linkUrl = [NSString stringWithFormat:@"%@",[AllrecordG objectForKey:@"Link"]];
[leftLabelG addTarget:self action:@selector(clickMe:linkUrl:) forControlEvents:UIControlEventTouchUpInside];
-(void)clickMe:(UIButton *)sender{
}
But here I get warning as "unused variable linkUrl".
I have studied different articles but somebody told that it is not possible to pass argument linke that. Anybody can tell me that how can i pass url for each button action and also how I retrieve those values. in the clickMe definition.
Thanks in advance.
Subclass UIButton like that :
MyButton.h
@interface MyButton : UIButton
{
NSString *_linkUrl;
}
@property (nonatomic, retain) NSString *linkUrl
MyButton.m
@implementation MyButton
@synthesize linkUrl = _linkUrl
Pass the linkUrl :
NSString *linkUrl = [NSString stringWithFormat:@"%@",[AllrecordG objectForKey:@"Link"]];
[leftLabelG addTarget:self action:@selector(clickMe:) forControlEvents:UIControlEventTouchUpInside];
[leftLabelG setLinkUrl:linkUrl];
Now you can get the linkUrl in your action like that :
-(void)clickMe:(MyButton *)sender{
NSString *url = sender.linkUrl;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With