小编Tit*_*zzi的帖子

Swift:选择搜索结果后返回tableview

我已经成功实现了搜索功能.我希望能够搜索我的列表,选择列表中的项目,然后在项目保持选中时返回主表视图.我该怎么做呢?

这是没有在搜索栏中输入任何选择或字符的tableview.项目没有详细视图.项目确实有更多可以检索的信息,例如url.当用户按下左上角的"邮件"按钮时,必须稍后检索此数据. 这是填充了完整列表子集的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)")
}
Run Code Online (Sandbox Code Playgroud)

但是,我没有成功地重新选择主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: …
Run Code Online (Sandbox Code Playgroud)

uitableview uisearchbar ios swift

6
推荐指数
1
解决办法
3544
查看次数

线性规划约束:优化变量的乘法

给定一个具有两个优化变量 ( x_in(t), x_out(t))的优化问题。对于任何时间步,当x_in非零时,x_out必须为零(反之亦然)。写成约束:

x_in(t)*x_out(t)=0
Run Code Online (Sandbox Code Playgroud)

Matlab 的linprog函数中如何包含这样的约束?

optimization matlab constraints linear-programming

4
推荐指数
1
解决办法
2594
查看次数