You have to delegate button action to controller. You should research it yourself but I'm gonna give you short example.
Let's assume you have a UITableViewCell
, and of course UITableView
has its own delegate methods like
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
these are selection of a cell, but you want to control a button action.
So you have a button inside cell like this
UIButton *someButton = [[UIButton alloc] initWithFrame:CGRectMake(0,0, 50, 50)];
[someButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:someButton];
this is in your cell class.
and .h
of your cell you write delegation like this.
@protocol SomeProtocol <NSObject>
- (void) buttonPressedInCell:(NSString *) data;
@end
and your delegate property in .h
@property (nonatomic, strong) id<SomeProtocol> delegate;
and your cell.m
finally you can give delegate to your button action
- (void) buttonClicked {
[delegate buttonPressedInCell];
}
so after this you can delegate this object whenver you want, in your case you want to give it to your UITableView
let's do it.
you have like a CustomTableViewCell
and your controller you must yourController<SomeProtocol>
and you have to delegate your cell like yourCell.delegate = self;
then implement your delegate method
- (void) buttonPressedInCell:(NSString *) data {
// do something like pushing new controller
//your data is in your controller now
}
Hope this helps you.
More information about delegation here