Reputation: 33
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
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
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
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