action:@selector(showAlert:) how to pass parameter in this showAlert method???? i am adding custom button in my tableviewcell in the action of that button i want to call showalert function and want to pass cell label in the method. please guide!!!!!


That's not possible. You have to create a method conforming to IBAction

- (IBAction)buttonXYClicked:(id)sender;

In this method you can create and call the UIAlertView. Don't forget to connect the button with the method in Interface Builder.

If you like to distinguish between multiple Buttons (e.g. you have one in each table cell) you can set the tag property of the button. And then check sender.tag from which button the click comes.

+1  A: 

Hello nic,

If you are using Button in Tableviewcell then u have to add tag value to each cell's button and set the method addTarget with id as a parameter.

Sample Code:

You have to Type Below code in cellForRowAtIndexPath method.


 // Set tag to each button
    cell.btn1.tag = indexPath.row; 
    [cell.btn1 setTitle:@"Select" forState:UIControlStateNormal];  // Set title 

 // Add Target with passing id like this
    [cell.btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];    

 return cell;


-(void)btnClick:(id)sender {

UIButton* btn = (UIButton *) sender;

 // here btn is the selected button...
    NSLog(@"Button %d is selected",btn.tag); 

// Show appropriate alert by tag values


Jay Vachhani