0
我想過濾一個UITableView而不需要涉及到搜索欄。不使用搜索欄來過濾UITableView
func filterResultsBasedOnSideViewController() {
print("filter value \(filterString)")
filteredPredicate = NSPredicate(format: "keyWords contains[c] %@", filterString)
filteredObjects = self.fetchedResultsController.fetchedObjects?.filter() {
return self. filteredPredicate!.evaluateWithObject($0)
} as! [myValues]?
self.tableView.reloadData()
}
但是在調用這個時真的沒有什麼事情發生。我在這裏完全錯了嗎?
而且我fetchedResultsController是誰的不知道的人如下:這裏
var fetchedResultsController: NSFetchedResultsController {
if _fetchedResultsController != nil {
return _fetchedResultsController!
}
let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
self.managedObjectContext = appDel.managedObjectContext
let fetchRequest = NSFetchRequest()
// Edit the entity name as appropriate.
let entity = NSEntityDescription.entityForName("myValues", inManagedObjectContext: self.managedObjectContext!)
fetchRequest.entity = entity
// Set the batch size to a suitable number.
fetchRequest.fetchBatchSize = 20
// Edit the sort key as appropriate.
let sortDescriptor = NSSortDescriptor(key: "sortID", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
let aFetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext!, sectionNameKeyPath: nil, cacheName: "Master")
aFetchedResultsController.delegate = self
_fetchedResultsController = aFetchedResultsController
do {
try _fetchedResultsController!.performFetch()
} catch {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
//print("Unresolved error \(error), \(error.userInfo)")
abort()
}
return _fetchedResultsController!
}
var _fetchedResultsController: NSFetchedResultsController? = nil
func controllerWillChangeContent(controller: NSFetchedResultsController) {
self.tableView.beginUpdates()
}
嘗試_fetchedResultsController =無調用filterResultsBasedOnSideViewController – AntonijoDev
@AntonijoDev謝謝,試過,但無法正常工作。 ( –
)你是否在fetchedResultsController方法中使用了puttin斷點?當你進入它時會發生什麼? – AntonijoDev