When reusing UISearchController I get the fatal error: Array index out of range

When reusing UISearchController I get the fatal error: Array index out of range

当我重复使用 UISearchController 时,我收到致命错误:数组索引超出范围。我阅读了一些材料,但没有找到答案。请帮助我。

我的代码如下

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

    return 1 ?? 0 // 1 ?? 0
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    var query: PFQuery = PFQuery(className: "NewsNow")

    if self.dataSearchResults == nil {
        return self.objects?.count ?? 0 
    } else {
        return self.dataSearchResults?.count ?? 0
    }
}

我修复了我的 func updateSearchResultsForSearchController

func updateSearchResultsForSearchController(searchController: UISearchController) {
    self.dataSearchResults?.removeAll(keepCapacity: false)
    var searchText = searchController.searchBar.text
    var query: PFQuery = PFQuery(className: "NewsNow")
    if searchController.active == true  {
        query.whereKey("nameNews", matchesRegex: searchText, modifiers: "i")
        self.tableView.reloadData() 
    }
    query.findObjectsInBackgroundWithBlock { (results:[AnyObject]?, error: NSError?) -> Void in
        self.dataSearchResults = results as? [PFObject]
        self.tableView.reloadData()
    }
     println(searchText)
}