Event not fired for UIButton in UIView in UITableViewCell

advertisements

In my UITableViewCell I have an UIImageView with a UIButton.

Here my code

My problem is that each time I try to click on the UIButton the UITableViewCell is triggered by the TouchUpInside event and not the UIBUtton.

Can you please help me?


This is my code.. here I use a UIButton inside the UITableViewCell and it works perfectly for me.. Hope this will help you..

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *CellIdentifier = @"ChildList";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    itsChildContactsTableView = tableView;
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:CellIdentifier] autorelease];
    }

    // we need a view to place our labels on.
    UIView *aTableCellContentView = [[UIView alloc] initWithFrame:CGRectZero];

    CGRect contentRect = aTableCellContentView.bounds;

    CGFloat boundsX = contentRect.origin.x;
    CGRect frame;

    frame = CGRectMake(boundsX + 10, 8, 200, 20);

    UIButton *aCallButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [aCallButton setImage:[UIImage imageNamed:@"call.png"] forState:UIControlStateNormal];
    [aCallButton addTarget:self action:@selector(dialNumber:) forControlEvents:UIControlEventTouchUpInside];
    [aCallButton  setTag:[indexPath row]];

    frame = CGRectMake(210, 14, 35, 35);
    aCallButton.frame = frame;

    UIButton *aEmailButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [aEmailButton setImage:[UIImage imageNamed:@"mail.png"] forState:UIControlStateNormal];
    [aEmailButton addTarget:self action:@selector(eMailContact:) forControlEvents:UIControlEventTouchUpInside];

    [aEmailButton  setTag:[indexPath row]];

    frame = CGRectMake(250, 14, 35, 35);

    aEmailButton.frame = frame;
    aTableCellContentView.backgroundColor = [UIColor whiteColor];
    [cell.contentView addSubview:aCallButton];
    [cell.contentView addSubview:aEmailButton];
    [cell.contentView addSubview:aTableCellContentView];
    [aTableCellContentView release];
    return cell;
}