我已经成功实现了搜索功能。我希望能够搜索我的列表,选择列表中的一个项目,然后返回到主表格视图,而项目仍然选择。我该怎么做呢?Swift:选择搜索结果后返回tableview
这是没有任何选择或字符键入到搜索栏的tableview。项目没有详细视图。项目确实具有可以检索的更多信息,例如,网址。稍后当用户按下左上方的“邮件”按钮时,必须检索此数据。
这是带搜索结果的列表。该单元格的灰色突出显示该单元格已被选中。现在如何返回到主桌面视图,同时保持选择?我只看到右上角的取消按钮,搜索栏顶部中间的交叉按钮以及键盘右下角的“搜索”按钮。在存储选择时,没有将您带回主表格视图。
根据建议的答案,我能够存储行的索引路径,使用下面的功能:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let rowToSelect = indexPath
println(rowToSelect)
selectedCellTitle = selectedCell?.textLabel?.text ?? ""
println("The stored cell is called \(selectedCellTitle)")
}
不过,我还没有成功地在主要的tableview重新选择行。我的代码如下。它看起来像常量“rowToSelect”不会转移到另一个函数(请参阅最后一行代码之前的那个)。我该如何解决?
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
if tableView == self.searchDisplayController!.searchResultsTableView {
cell.textLabel?.text = filteredPublications[indexPath.row].valueForKey("fullTitle") as? String
cell.detailTextLabel?.text = filteredPublications[indexPath.row].valueForKey("journal") as? String
} else {
cell.textLabel?.text = publications[indexPath.row].valueForKey("fullTitle") as? String
cell.detailTextLabel?.text = publications[indexPath.row].valueForKey("journal") as? String
self.tableView.selectRowAtIndexPath(rowToSelect, animated: true, scrollPosition: .Top)
}
return cell
}
视图控制器标签添加到您的时候您放入视图中,选择单元格时存储标签,循环浏览表格视图的子视图,如果标签是存储的标签,则选择正确的单元格 – milo526 2015-04-01 13:46:24
在此方法中,用户使用哪个按钮从搜索结果列表到fu我会列出吗? – 2015-04-01 21:36:05
我编辑了我的反应,我希望这能为你澄清一些问题 – milo526 2015-04-02 13:42:17