I wrote the code to search for values ​​in the table, when I click on the search bar, the table disappears, but the value I need does not appear.

What could be the problem?

Update

var find: [List] = [] var searchResult: [List] = [] let context: NSManagedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext var detailViewController: MainVC? = nil var frc : NSFetchedResultsController = NSFetchedResultsController() var searchController: UISearchController! func getFetchResultsController() ->NSFetchedResultsController { frc = NSFetchedResultsController(fetchRequest: listFetchRequest(), managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil) return frc } func listFetchRequest() -> NSFetchRequest{ let fetchRequest = NSFetchRequest (entityName: "List") let sortDescriptor = NSSortDescriptor(key: "item", ascending: true) fetchRequest.sortDescriptors = [sortDescriptor] return fetchRequest } override func viewDidLoad() { super.viewDidLoad() frc = getFetchResultsController() frc.delegate = self do { try frc.performFetch() } catch {} if let split = self.splitViewController { let controllers = split.viewControllers self.detailViewController = (controllers[controllers.count-1] as! UINavigationController).topViewController as? MainVC } searchController = UISearchController(searchResultsController: nil) tableView.tableHeaderView = searchController.searchBar searchController.searchResultsUpdater = self searchController.dimsBackgroundDuringPresentation = false } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func controllerDidChangeContent(controller: NSFetchedResultsController) { tableView.reloadData() } // MARK: - Table view data source override func numberOfSectionsInTableView(tableView: UITableView) -> Int { let numberOfSections = frc.sections?.count return numberOfSections! } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if searchController.active { return searchResult.count } else { //return find.count let numberOfRowsInSection = frc.sections?[section].numberOfObjects return numberOfRowsInSection! } // #warning Incomplete implementation, return the number of rows } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) let search = (searchController.active) ? searchResult[indexPath.row] : frc.objectAtIndexPath(indexPath) as! List print(search) //Configure the cell.. cell.textLabel!.text = search.item let qty = search.qty let address = search.address cell.detailTextLabel?.text = "Dukan Sayi: \(qty)\(address)" return cell } override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { if searchController.active { return false } else { return true } } override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { let managedObject : NSManagedObject = frc.objectAtIndexPath(indexPath) as! NSManagedObject context.deleteObject(managedObject) do { try context.save() } catch {} } func updateSearchResultsForSearchController(searchController: UISearchController) { if let searchText = searchController.searchBar.text { filterContent(searchText) print(searchText) tableView.reloadData() } } func filterContent(searchText: String) { searchResult = find!.filter({ ( a: List) -> Bool in let nameMatch = a.item.rangeOfString (searchText, options: NSStringCompareOptions.CaseInsensitiveSearch) return nameMatch != nil }) } 
  • Can anyone suggest an idea? ) - Rufat
  • No ideas. Do you want a plus sign? - Denis
  • A minimal example of your problem that would compile would be very helpful. And I would suggest that you find a tutorial on this issue and see how it is implemented. - Max Mikheyenko
  • the problem is that the searchResult function does not find the necessary data in core data, respectively, does not display them in a table (filter). The examples mainly concern the array ev, as I understand it with the base a little differently and I did not find examples of normal ones. - Rufat

0