Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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
Xcode Swift-具有多个选择的搜索表视图_Xcode_Swift_Uitableview_Search_Ios9 - Fatal编程技术网

Xcode Swift-具有多个选择的搜索表视图

Xcode Swift-具有多个选择的搜索表视图,xcode,swift,uitableview,search,ios9,Xcode,Swift,Uitableview,Search,Ios9,我遵循了Vea软件()的教程,在xcode 7、ios 9上创建了一个带有搜索栏的表视图。现在我需要从表视图中选择多行,在选中时在每行上添加一个复选标记,问题是当我使用搜索栏时,复选标记不再与行匹配 这是我的密码: class SportSearchTableViewController: UITableViewController, UISearchResultsUpdating { let appleProducts = ["Mac","iPhone","Apple Watch","iPa

我遵循了Vea软件()的教程,在xcode 7、ios 9上创建了一个带有搜索栏的表视图。现在我需要从表视图中选择多行,在选中时在每行上添加一个复选标记,问题是当我使用搜索栏时,复选标记不再与行匹配

这是我的密码:

class SportSearchTableViewController: UITableViewController, UISearchResultsUpdating {

let appleProducts = ["Mac","iPhone","Apple Watch","iPad"]
var filteredAppleProducts = [String]()
var resultSearchController = UISearchController()

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.deselectRowAtIndexPath(indexPath,animated: true)
    let selectedRow = tableView.cellForRowAtIndexPath(indexPath)!
    if selectedRow.accessoryType == UITableViewCellAccessoryType.None {
        selectedRow.accessoryType = UITableViewCellAccessoryType.Checkmark
        selectedRow.tintColor = UIColor.blueColor()
    } else {
        selectedRow.accessoryType = UITableViewCellAccessoryType.None
    }
}


override func viewDidLoad() {
    super.viewDidLoad()

    self.resultSearchController = UISearchController(searchResultsController: nil)
    self.resultSearchController.searchResultsUpdater = self
    self.resultSearchController.dimsBackgroundDuringPresentation = false
    self.resultSearchController.searchBar.sizeToFit()

    self.tableView.tableHeaderView = self.resultSearchController.searchBar

    self.tableView.reloadData()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if (self.resultSearchController.active)
    {
        return self.filteredAppleProducts.count
    }
    else
    {
        return self.appleProducts.count
    }
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell?

    if (self.resultSearchController.active)
    {
        cell!.textLabel?.text = self.filteredAppleProducts[indexPath.row]

        return cell!
    }
    else
    {
        cell!.textLabel?.text = self.appleProducts[indexPath.row]

        return cell!
    }
}


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

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

    self.tableView.reloadData()
}

有人知道怎么解决吗?

你解决了吗?我也有这个问题