Shakeel Ahmed
Shakeel Ahmed

Reputation: 33

How to call a method on button click on custom button

I have CustomCell I want that when I click a button which is in CustomCell that it should alert. So how to access the method of that CustomCell

  @interface CustomCell : UITableViewCell {

IBOutlet UIImageView    *imageViewCell;
IBOutlet UILabel        *theTitle;
IBOutlet UIButton*imageButton;


  }

  @property(nonatomic,retain) IBOutlet UIButton*imageButton;
  @property(nonatomic,retain) UIImageView *imageViewCell;
  @property(nonatomic,retain) UILabel *theTitle;

 -(IBAction)imageButtonAction;

 @end



     @implementation CustomCell

     @synthesize imageViewCell;
     @synthesize theTitle;

    -(IBAction)imageButtonAction{


     }

Instead of calling this method here I want that this method should envoke in the class where I am using CustomCell any idea how to do this.

Upvotes: 0

Views: 1019

Answers (3)

Rushi
Rushi

Reputation: 4500

In your cellForRowAtIndexPath add this code :

[cell.imageButton addTarget:self action:@selector(imageButtonAction) forControlEvents:UIControlEventTouchUpInside];

Declare and define this -(IBAction)imageButtonAction; function in that particular class where you are using this customized cell.

Upvotes: 2

Monish Bansal
Monish Bansal

Reputation: 509

Use below line in cellforrowatindexpath: method

[cell.imageButton addTarget:self action:@selector(imageButtonAction) forControlEvents:UIControlEventTouchUpInside];

and dont forget to make method for imageButtonAction

Upvotes: 0

BhushanVU
BhushanVU

Reputation: 3455

Add below line in your cellforrow at index path after you specify cell. It will call the method when you click on button in cell

[cell.button addTarget:self action:@selector(imageButtonAction) forControlEvents:UIControlEventTouchUpInside];

Upvotes: 1

Related Questions