【问题标题】:How can i call search tableview delegate with SQLLite我如何使用 SQLite 调用搜索 tableview 委托
【发布时间】:2018-01-03 18:32:30
【问题描述】:

我准备了表格视图。如下图所示,有一个 sqllite db。 .但是搜索委托功能不起作用。

var dictionaries = [[String:AnyObject]]() //
var filteredDogs = [[String:AnyObject]]()
var searchController: UISearchController!
var resultsController = UITableViewController()

func updateSearchResultsForSearchController(searchController: UISearchController) {

    self.filteredDogs =  self.dictionaries.filter{(dict:[String:AnyObject]) -> Bool in

        if dict.lowercaseString.containsString(self.searchController.searchBar.text!.lowercaseString)
        {
            return true

        }
        else
        {
            return false

        } 
    }
    //Update results table


    self.resultsController.tableView.reloadData()
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {


    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! RowTableViewCell


    if tableView == self.tableView
    {
        let row = self.dictionaries[indexPath.row]
        cell.language1.text = row["foreign_language"] as? String
        cell.language2.text = row["native_language"] as? String


    }
    else
    {
        let row = self.filteredDogs[indexPath.row]
        cell.language1.text = row["foreign_language"] as? String
        cell.language2.text = row["native_language"] as? String


    }
    return cell
}

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

    let row = self.dictionaries[indexPath.row]
    self.speechText((row["foreign_language"] as? String)!, language: (row["language"] as? String)!)

    let indexPath = self.tableView.indexPathForSelectedRow
    if((indexPath) != nil){
        self.tableView.deselectRowAtIndexPath(indexPath!, animated: true)
    }
}

enter image description here

【问题讨论】:

  • 您使用哪个数组来填充您的 UITableView?
  • 字典 --> native_langauage 。 cell.language1.text = row["native_language"] as?字符串
  • 你能把你所有的UITableView相关代码贴出来吗?
  • 请用该代码编辑您的答案,在 cmets 中不可读
  • 哦。对不起。我是论坛的新手。 :) 我添加到下面。你能检查一下吗?谢谢你

标签: ios swift xcode sqlite uitableview


【解决方案1】:
 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {


    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! RowTableViewCell


    if tableView == self.tableView
    {
        let row = self.dictionaries[indexPath.row]
        cell.language1.text = row["foreign_language"] as? String
        cell.language2.text = row["native_language"] as? String


    }
    else
    {
        let row = self.filteredDogs[indexPath.row]
        cell.language1.text = row["foreign_language"] as? String
        cell.language2.text = row["native_language"] as? String


    }
    return cell
}

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

    let row = self.dictionaries[indexPath.row]
    self.speechText((row["foreign_language"] as? String)!, language: (row["language"] as? String)!)

    let indexPath = self.tableView.indexPathForSelectedRow
    if((indexPath) != nil){
        self.tableView.deselectRowAtIndexPath(indexPath!, animated: true)
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多