找不到实际的“详细信息按钮”;在 tableView 的行中

发布于 2024-09-07 07:51:36 字数 619 浏览 5 评论 0原文

当我单击 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);
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱花坊 2024-09-14 07:51:37

附件视图是 UIView 而不是 UIButton。也许将其转换为按钮会导致描述方法失效。只是一个猜测。

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

若言繁花未落 2024-09-14 07:51:37

最好的选择是访问视图中的按钮。也许像这样

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

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

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文