Passing Parameters to Selector action Passing Parameters to Selector action objective-c objective-c

Passing Parameters to Selector action


While you can not pass the URL directly to the selector, you can pass the button itself. So my suggestion would be to tag button according to your cell row and create action like this:

void goToAddress: (id) sender {   UIButton *button = (UIButton*) sender;   if (button.tag == ..) {   ...  }}

Then, in that method you can "look up" URL from the cell with the number equal to tag of the button.

Other than that, I am fairly sure it's impossible to pass custom parameters or more than one parameter in button's selector. Please correct me if I'm wrong.

Hope that helps.


You just need : when passing parameter to a selector if you need to pass one parameter.

[cell.buyTicketOutlet addTarget:self action:@selector(pushToTicketURL:) forControlEvents:UIControlEventTouchUpInside];

Basically : means you are passing an arguement to the selector and on the receiving end you could define your selector method with the object.


Refering to fDmitry's response,

Here's the full code I used for his explanation. It works phenomally :). Thank you to the Omar Abdelhafith, whose link helped me, and fDmitry for getting me on the right track :)

-(void)pushToTicketURL:(id)sender{    UIButton *button = (UIButton*)sender;    UIView *view = button.superview; //Cell contentView    SearchTableCell *cell = (SearchTableCell *)view.superview;    NSLog(@"%@",cell.EventTitle.text); //Cell Text    UIViewController *webViewController = [[UIViewController alloc] init];    webViewController.title = cell.EventTitle.text;    [webViewController.title sizeWithFont:10];    UIWebView *uiWebView = [[UIWebView alloc] initWithFrame: CGRectMake(0,0,320,370)];    [uiWebView loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:cell.EventTicketURL]]];    [webViewController.view addSubview:uiWebView];    [uiWebView release];    [self.navigationController pushViewController:webViewController animated:YES];}

This snippet of code helped me so much and hope it helps anyone else whose falls into the same problem :).