[英]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.