【问题标题】:getting the index path of section when pressing on a button in this section按下本节中的按钮时获取节的索引路径
【发布时间】:2018-01-15 17:49:22
【问题描述】:

我有一个包含部分而不是行的表格视图,每个部分都包含一个按钮,按下此按钮时已为该按钮设置了一个不作为功能,按下此按钮时我需要获取此部分的 indexPath,我使用了那些功能:

 NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
 NSString *orderId = [self.tableValues objectAtIndex:indexPath.section];

都返回 nil 问题出在 indexPath 值上, 但知道为什么吗? 谢谢

【问题讨论】:

    标签: objective-c uitableview


    【解决方案1】:

    那是因为你点击的是按钮而不是你的单元格。

    为了让它工作,给按钮添加标签,当点击时,点击按钮时获取标签。所以你的代码会变成

    NSString *orderId = [self.tableValues objectAtIndex:tag_that_you_get_in_IBAction];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-24
      • 1970-01-01
      • 1970-01-01
      • 2020-12-15
      • 2012-03-09
      • 2021-11-18
      • 2020-01-25
      • 2023-03-19
      相关资源
      最近更新 更多