Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios TableView搜索栏冻结_Ios_Uitableview_Swift - Fatal编程技术网

Ios TableView搜索栏冻结

Ios TableView搜索栏冻结,ios,uitableview,swift,Ios,Uitableview,Swift,使用“我的tableview”设置的标准搜索栏。最多可以搜索1000个值(这应该不会太昂贵) 问题:如果我在中输入单个字符,搜索栏将延迟30-90秒。CPU和内存为100%。我是否错误地实现了searchbardel TableView单元 过滤代码 你在真实设备上测试过吗?如果你在xcode6或6.1的模拟器上测试。xcode6.1的sumulator多次出现这种情况。如果您没有在真实设备上测试,可能在真实设备上找不到此问题。在两台实际设备上进行了测试,但都存在问题(iphone 5和ipho

使用“我的tableview”设置的标准搜索栏。最多可以搜索1000个值(这应该不会太昂贵)

问题:如果我在中输入单个字符,搜索栏将延迟30-90秒。CPU和内存为100%。我是否错误地实现了searchbardel

TableView单元 过滤代码
你在真实设备上测试过吗?如果你在xcode6或6.1的模拟器上测试。xcode6.1的sumulator多次出现这种情况。如果您没有在真实设备上测试,可能在真实设备上找不到此问题。在两台实际设备上进行了测试,但都存在问题(iphone 5和iphone 6 plus),请尝试在后台运行搜索,并在搜索完成后弹出到主线程。问题很明显是你的搜索时间太长了
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = self.tableView.dequeueReusableCellWithIdentifier("RestaurantCell") as UITableViewCell
    var name : Name
    // Check to see whether search results table is being displayed
    if tableView == self.searchDisplayController!.searchResultsTableView {
        name = self.filteredNames[indexPath.row]
    } else {
        name = self.names[indexPath.row]
    }

    cell.textLabel?.text = name.name
    cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
    return cell
}
func filterContentForSearchText(searchText: String, scope: String = "All") {
    self.filteredNames = self.names.filter({( name : Name) -> Bool in
        var categoryMatch = (scope == "All") || (name.city == scope)
        var stringMatch = name.name.rangeOfString(searchText)
        self.filterRestaurants(searchText)
        return categoryMatch && (stringMatch != nil)
    })
}

func filterRestaurants(filteredObject: String) {
    selectFilteredRestaurantArray = self.selectRestaurantArray.filter()  {
        if let type = ($0 as PFObject)["Name"] as? String {
            return type.rangeOfString(filteredObject) != nil
        } else {
            return false
        }
    }
}

func searchDisplayController(controller: UISearchDisplayController!, shouldReloadTableForSearchString searchString: String!) -> Bool {
    self.filterContentForSearchText(searchString)
    return true
}

func searchDisplayController(controller: UISearchDisplayController!, shouldReloadTableForSearchScope searchOption: Int) -> Bool {
    self.filterContentForSearchText(self.searchDisplayController!.searchBar.text)
    return true
}