问题描述
我对用户单击我的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 (将#修改为@)