搜索TableView无法选择行 [英] Searching TableView can't select row

查看:121
本文介绍了搜索TableView无法选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在搜索tableView时,每次尝试选择一行时,它只会带我回到未搜索的tableView中.我想念什么?当不通过表格进行过滤时,segue可以完美地工作.激活searchBar后,选择行的能力就会消失.

While searching a tableView, every time I try to select a row it just takes me back to the unsearched tableView. What am I missing? the segue works perfectly when not filtering through the table. The ability to select a row just disapears while the searchBar is activated.

import UIKit
import Foundation

class BenchmarkWODViewController: UITableViewController, UISearchResultsUpdating {

    var WodList = [WOD]()
    var FilteredWodList = [WOD]()
    var Keyword = ""
    var searchController : UISearchController?
    var index = Int()

    @IBAction func backButton(sender: AnyObject) {
        self.navigationController?.popViewControllerAnimated(true)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        for wodData in BenchmarkWODs.library {
            let wod = WOD(dictionary: wodData)
            WodList.append(wod)
    }

    // Search Bar
        self.searchController = UISearchController(searchResultsController: nil)
        self.searchController?.searchBar.autocapitalizationType = .None
        self.tableView.tableHeaderView = self.searchController?.searchBar
        self.searchController?.searchResultsUpdater = self
        self.Keyword = ""
        definesPresentationContext = true

        self.filterByName()
    }


    func filterByName(){
        self.FilteredWodList = self.WodList.filter({ (wod: WOD) -> Bool in
            if self.Keyword.characters.count == 0 {
            return true
        }

        if (wod.name?.lowercaseString.rangeOfString(self.Keyword.lowercaseString)) != nil {
            return true
        }
        return false
    })
        self.tableView.reloadData()
    }


    // Search Bar Function
    func updateSearchResultsForSearchController(searchController:     UISearchController) {
        Keyword = searchController.searchBar.text!
        self.filterByName()
    }



    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.FilteredWodList.count
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCellWithIdentifier("BenchmarkCell", forIndexPath: indexPath) as UITableViewCell
        let wod = self.FilteredWodList[indexPath.row]

        if let wodName = wod.name {
        cell.textLabel?.text = wodName
    }
        return cell
    }



    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    self.filterByName()
        self.performSegueWithIdentifier("showBenchmarkDetail", sender: nil)
    }

}

推荐答案

在玩转后弄清楚了它.显然,添加以下代码可以解决此问题.

Figured it out after playing around. Apparently adding the below code corrects the problem.

searchController?.dimsBackgroundDuringPresentation = false

这篇关于搜索TableView无法选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆