0

UISearchResultsUpdating でそのデータを検索したいデータを持つ NSMutableArray があります。function にあるコードではupdateSearchResultsForSearchController、すべて正常に動作しています。ただし、文字を入力すると、どの文字でもテーブルビューセルがポップアップしないという問題があります。空白で、何も検索しません。これについて何か助けはありますか?

重要な 2 つの変数。

NSMutubaleArray 変数

var toDoItems = NSMutableArray()

コード内の別の便利な変数

var filteredAppleProducts = [String]()

ここに私の updateSearchResultsForSearchController 関数があります

func updateSearchResultsForSearchController(searchController: UISearchController)
{
    self.filteredAppleProducts.removeAll(keepCapacity: false)                

    let searchPredicate = NSPredicate(format: "title CONTAINS[c] %@", searchController.searchBar.text!)
    let array = (toDoItems as NSArray).filteredArrayUsingPredicate(searchPredicate)
    self.filteredAppleProducts = array as! [String]

    tbl!.reloadData()
}

これは私の CellForRowatIndexPath と私の numberOfRowsInSection です。

cellForRowAtIndexPath

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

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

    if (self.resultSearchController.active)
    {
        cell.lbl.text = self.filteredAppleProducts[indexPath.row]                
        return cell
    }
    else
    {
        let toDoItem: NSDictionary = toDoItems.objectAtIndex(indexPath.row) as! NSDictionary
        cell.lbl.text = toDoItem.objectForKey("itemTitel") as? String                
        return cell            
    }            
}

numberOfRowsInSection

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{

    if (self.resultSearchController.active)
    {
        return self.filteredAppleProducts.count
    }
    else
    {            
        return toDoItems.count            
    }        
}
4

0 に答える 0