【问题标题】:Can't find the actual 'detail button' in a tableView's row在 tableView 的行中找不到实际的“详细信息按钮”
【发布时间】:2010-06-30 18:30:57
【问题描述】:

当我单击 tableView 的详细信息按钮时...我可以设法获取节号、行号甚至单元格本身...但是为什么无法获得实际的“详细信息按钮”? (NSLog 总是为按钮显示“(null)”。)

- (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);
}

【问题讨论】:

    标签: iphone uitableview accessorytype accessoryview


    【解决方案1】:

    附件视图是 UIView 而不是 UIButton。也许将其转换为按钮会抛出描述方法。只是猜测。

    【讨论】:

    • 那么我们该如何解决呢?获取视图...然后获取内部按钮?但是怎么做呢?
    • 不确定,我从来没有做过。我将首先在调试器中检查附件视图的视图层次结构,以查看您正在处理哪些类以及以什么顺序处理。为什么你仍然需要检查附件视图?你已经知道它是什么类型了,它被击中了,它在哪一行。你还需要知道什么?
    【解决方案2】:

    最好的办法是访问视图中的按钮。也许像

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

    这假设您在附件视图中只有您的详细信息按钮,将其从子视图中挑选出来,并在 detailBtn 中创建您对它的引用 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-17
      相关资源
      最近更新 更多