I understand how to get button clicks if I have a button within a row of UITableView but what I cannot figure out is the correct way to add a button to a UITableViewCell subclass and get the clicks for it within my UITableView class. I think I'm making the mistake of putting everything into the layoutSubviews method. Can somebody please point me in the right direction?
-(void) layoutSubviews
{
// UIButton *myButton1; <- This is declared as a property in my subclass header file
[super layoutSubviews];
//self.textLabel.frame = CGRectMake(0, 0, 40, 20);
// cell.textLabel.text = timeElapsed;
self.textLabel.frame = CGRectMake( 5, 5, 80, self.frame.size.height - 10 );
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Don't need UIButton alloc because method below does it for us..
myButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//CGRect cellFrame = [self.tableView rectForRowAtIndexPath:indexPath];
CGRect cellFrame = self.frame;
myButton1.tag = idButton;
int nButtonWidth = 80;
int nButtonHeight = 30;
int nActualCellWidth = cellFrame.size.width - 40;
int nButtonDeltaX = ( nActualCellWidth - nButtonWidth ) / 2;
int nButtonDeltaY = ( cellFrame.size.height - nButtonHeight ) / 2;
myButton1.frame = CGRectMake( nButtonDeltaX, nButtonDeltaY, nButtonWidth, nButtonHeight );
[myButton1 setTitle:@"OK" forState:UIControlStateNormal];
// PDS: Add delaget for stopwatch clicking..
// [myButton1 addTarget:self action:@selector(buttonClickedStopWatch:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:myButton1];
[self.contentView bringSubviewToFront:myButton1];
}