如何解决indexPathForSelectedRow返回Section中的索引路径
我对用户单击我的TableView时返回的IndexPath有疑问。
我有一个对象数组,可以循环遍历并传递到字典中,如下所示
terms = Term.terms()
// Create the terms dictionary
for term in terms {
let termKey = String(term.Abbreviation.prefix(1))
if var termValues = termsDictionary[termKey] {
termValues.append(term)
termsDictionary[termKey] = termValues
} else {
termsDictionary[termKey] = [term]
}
}
//get the section Titles from the dictionary's ket and sort them in ascending order
termsSectionTitles = [String](termsDictionary.keys)
termsSectionTitles = termsSectionTitles.sorted(by: { $0 < $1 })
到目前为止一切都很好。然后,当用户单击单元格时,这些控件将正确填充表格视图。然后,我需要找到所选单元格的对象。
例如,用户选择B部分中的第三个单元格,它返回2作为索引路径。我知道为什么,但这与我需要的对象不符。
是否有一种获取单元格的索引路径而无视标题的方法?
guard
segue.identifier == "ShowDetailSegue",let indexPath = tableView.indexPathForSelectedRow,let detailViewController = segue.destination as? DetailViewController
else {
return
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。