Use Delegate Methods For Example
Make SubClass of UITableViewCell
Declare Delegate Methods
@protocol CustomCellDelegate <NSObject>
-(void)btnClikced;
@end
// InterFace
@interface CustomCell : UITableViewCell
@property(nonatomic,retain) id<CustomCellDelegate> delegate;
//implementation
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
UIButton *btn=[UIButton buttonWithType:UIButtonTypeContactAdd];
[btn addTarget:self action:@selector(btnTapped) forControlEvents:UIControlEventTouchUpInside];
self.accessoryView=btn;
}
return self;
}
-(void)btnTapped{
[self.delegate btnClikced];
}
in your ViewController
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.delegate = self;
return cell;
}
- (void)btnClikced{
//button action code here
}