views:

20

answers:

1

When I click on my tableView's detail-button... I can manage to get the section number, the row number, and even the cell itself... but why is the actual "detail button" unobtainable? (NSLog always displays "(null)" for the button.)

- (void) tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    int section = indexPath.section;
    int row     = indexPath.row;

    UITableViewCell *aCell = [tableView cellForRowAtIndexPath:indexPath];
    UIButton *detailButton = (UIButton *)[aCell accessoryView];

    // Why is detailButton null?
    NSLog(@"accessory button tapped for row with index path %d x %d \n cell=(%@) \n button=(%@)", section, row, aCell, detailButton);
}
+1  A: 

The accessory view is a UIView not a UIButton. Perhaps casting it to a button throws off the description method. Just a guess.

TechZen
So how would we fix that? Get the view... then get the button inside? But how?
Helen
Not sure, I've never done it. I would start with examining the view hierarchy of the accessory view in the debugger to see what classes you are dealing with and in what order. Why do you need to examine the accessory view anyway? You already know what kind it is, that it has been hit and which row it is in. What else do you need to know?
TechZen