【问题标题】:didSelectRowAtIndexPath returning a very large numberdidSelectRowAtIndexPath 返回一个非常大的数字
【发布时间】:2015-06-22 19:18:11
【问题描述】:

尝试使用以下方法查找 TableViewController 中触及的行号:

 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let indexPath = tableView.indexPathForSelectedRow();
    let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as UITableViewCell?;
    NSLog("Current Cell = %d", currentCell!)
}

如果您按下相同的单元格,它会返回相同的数字,但会出现非常大的数字,例如 410772272 或 409747056。在两个单元格测试中,我期待的是 1 或 2。如果您使用 %i 或返回相同的数字%d。

任何见解或我是否完全使用了错误的电话。

【问题讨论】:

  • currentCell! 是指向表格视图单元格的 指针 ...您的意思是 NSLog("Current row = %d", indexPath.row) 吗?

标签: swift didselectrowatindexpath


【解决方案1】:

NSLog("Current Cell = %d", currentCell!)

您正在打印存储在 currentCell 变量中的内存地址 - 这就是为什么它是一个如此高的数字。

可以通过indexPath.row获取行号;你甚至不需要let currentCell = 行。

【讨论】:

  • 确实,语法似乎是:NSLog("Current Row = %i", indexPath!.row)
猜你喜欢
  • 1970-01-01
  • 2023-02-18
  • 1970-01-01
  • 2021-11-26
  • 1970-01-01
  • 2012-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多