标签云

微信群

扫码加入我们

WeChat QR Code

Although there seems to be plenty of information on UISearchControllers, many of the approaches I have found have been deprecated in iOS 8. Most tutorials I have found use UISearchDisplayController, which is deprecated, and even the documentation on UISearchController uses convenience methods that have also been deprecated. I'm looking for someone who knows how to successfully search items in a UITableView that is backed by core data in iOS 8. Currently I have a table view that that fetches and displays points of interest saved from a map view. Pretty standard boilerplate stuff - just persisting and fetching entities. The challenging part of this is adding a UISearchController, which recently replaced the UISearchDisplayController,to the table view that is backed by core data (the tableview displays anypoint of interest entity persisted to the data store). Using core data instead of a standard array is where the complication begins, and there isn't sufficient documentation using this particular approach. Open to any and all suggestions.To kick things off, lets consider that I have stored my fetched items from core data in a mutable array. How would we go about using that to filter our table view?self.searchResults = [NSMutableArray arrayWithCapacity:[[self.fetchController fetchedObjects] count]];


Hi.I think your question, as it stands, is a bit too broad for SO.Can you elaborate on your particular situation: how is the base tableView constructed; do you want it filtered in situ, or a new tableView presented with the search results?Which deprecated methods are you trying to avoid?

2019年04月19日07分53秒

There doesn't appear to be any clear documentation once Apple deprecated the UISearchDisplayController. The intent of the question was to be a little broad to open up best practices when adding a search bar to a tableview that has been backed by core data.

2019年04月20日07分53秒

The deprecated method is the UISearchDisplayController, which has been replaced by UISearchController. The problem is there doesn't seem to be any clear documentation for using this with core data. Most of everything that I have found either still uses the UISearchDisplayController, or the documentation focuses on using standard arrays apposed to core data.

2019年04月19日07分53秒

I've done that I'm talking about filtering the data in the table view

1970年01月01日00分03秒

What is not working? Did you implement the UISearchResultsUpdating protocol method updateSearchResultsForSearchController(_:)?? You stated explicitly that you were using an array, so I addressed that issue as well.

2019年04月20日07分53秒

I'm working through this and i'll have more to share in a day or so. I currently can fetch and retrieve data, but my problem is filtering a table view. How would you go about invalidating the fetched results controller?

1970年01月01日00分03秒

Your suggestion to invalidate the fetched results controller pointed me in the right direction, thanks!

2019年04月20日07分53秒