开发者

Can't find the actual 'detail button' in a tableView's row

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" unob开发者_Go百科tainable? (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);
}


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


Your best bet is to access the button within the view. Perhaps something like

UIButton* detailBtn = [[UIButton alloc] init];
for (UIButton* detail in aCell.accessoryView.subviews)
{
     detailBtn = detail;
}

This assumes you only have your detail button in the accessory view, picks it out of the subview, and creates your references to it in detailBtn :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜