简体   繁体   English

无法访问表格视图单元的索引路径

[英]Index Path for the table view cell is not being accessible

I am trying a new sample project and in that i'm adding a table view to a ViewController and on tap of each table view cell it is navigated to a detail view controller by making it a push segue . 我正在尝试一个新的示例项目,在此过程中,我向ViewController添加了一个table view ,并在每个表格视图单元格上点击,通过将其push segue )导航到详细视图控制器。

In prepareForSegue() method,indexPath for the selected tableViewCell is retuned as nil. prepareForSegue()方法中,将所选tableViewCell indexPath重新调整为nil。

Here's the method, 这是方法

func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
    self.performSegueWithIdentifier("detail_segue", sender: self)
}

func prepareForSegue(segue: UIStoryboardSegue?,sender: AnyObject!){

  if(segue!.identifier == "detail_segue"){
      var indexPath = self.tableView.indexPathForSelectedRow()
      let detailViewController = segue!.destinationViewController as! DetailViewController
          detailViewController.sampleDetail = samplesArray[indexPath!.row] as! Sample
    }
} 

Let me know where i'm going wrong? 让我知道我要去哪里错了? Thanks in advance.. 提前致谢..

You can try this : 您可以尝试以下方法:

var index = self.tableView.indexPathForCell(sender as UITableViewCell)!

I think maybe your tableviewcell.selectionStyle is None, so self.tableView.indexPathForSelectedRow() will return nil because it is really have no selected row. 我认为也许您的tableviewcell.selectionStyle为None,所以self.tableView.indexPathForSelectedRow()将返回nil,因为它实际上没有选定的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 断言没有重用表单元格的索引路径 - Assert no index path for table cell being reused 没有索引路径表格单元格在Swift中重用 - No index path for table cell being reused in Swift 没有重用表单元格的索引路径 - No index path for table cell being reused 用户当前正在重新排列(移动)的表视图单元格的索引路径是什么? - What is the index path of a table view cell that is currently being rearranged (moved) by the user? “表单元没有索引路径被重用”导致应用程序崩溃 - “no index path for table cell being reused” leading to app crash 核心数据:没有重用表单元的索引路径,单元消失了 - Core Data: no index path for table cell being reused, Cells disappearing iOS 6/7中“无法使用表格单元索引路径”消息的含义是什么? - What is the meaning of the “no index path for table cell being reused” message in iOS 6/7? 如何在swift中同时显示表格视图单元格索引路径和集合视图索引路径? - How to show table view cell index path and collection View Index path at the same time in swift? 表格视图单元格中的按钮未响应其索引路径 - button in table view cell not responding with its index path 是否可以在 swift 中显示表格视图单元格索引路径和集合视图索引路径? - Is it possible to show table view cell index path and collection View Index path in swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM