More reliable search results.
[IMPROVED] MP-14: Made searchResultsTableView more reliable.
This commit is contained in:
parent
0d638a4c3f
commit
941b428cfc
2
External/Pearl
vendored
2
External/Pearl
vendored
@ -1 +1 @@
|
||||
Subproject commit b45e33014850ece1a42afb4ac5363aadd0ea90d6
|
||||
Subproject commit d247edba08f70994bb8b0cb50413aedfa963cacd
|
@ -40,8 +40,8 @@
|
||||
</MacroExpansion>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Debug"
|
||||
|
@ -125,66 +125,89 @@
|
||||
[self.searchDisplayController.searchResultsTableView reloadData];
|
||||
}
|
||||
|
||||
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
|
||||
|
||||
[self.searchDisplayController.searchResultsTableView beginUpdates];
|
||||
}
|
||||
|
||||
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
|
||||
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
|
||||
|
||||
UITableView *tableView = self.searchDisplayController.searchResultsTableView;
|
||||
switch(type) {
|
||||
|
||||
case NSFetchedResultsChangeInsert:
|
||||
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
|
||||
break;
|
||||
|
||||
case NSFetchedResultsChangeDelete:
|
||||
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
||||
break;
|
||||
|
||||
case NSFetchedResultsChangeUpdate:
|
||||
[self configureCell:[tableView cellForRowAtIndexPath:indexPath]
|
||||
inTableView:tableView atIndexPath:indexPath];
|
||||
break;
|
||||
|
||||
case NSFetchedResultsChangeMove:
|
||||
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
|
||||
withRowAnimation:UITableViewRowAnimationFade];
|
||||
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
|
||||
withRowAnimation:UITableViewRowAnimationFade];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo
|
||||
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
|
||||
|
||||
UITableView *tableView = self.searchDisplayController.searchResultsTableView;
|
||||
switch(type) {
|
||||
|
||||
case NSFetchedResultsChangeInsert:
|
||||
[tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]
|
||||
withRowAnimation:UITableViewRowAnimationFade];
|
||||
break;
|
||||
|
||||
case NSFetchedResultsChangeDelete:
|
||||
[tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]
|
||||
withRowAnimation:UITableViewRowAnimationFade];
|
||||
break;
|
||||
}
|
||||
}
|
||||
// See MP-14, also crashes easily on internal assertions etc..
|
||||
//- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
|
||||
//
|
||||
// [self.searchDisplayController.searchResultsTableView beginUpdates];
|
||||
//}
|
||||
//
|
||||
//- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
|
||||
// atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
|
||||
//
|
||||
// UITableView *tableView = self.searchDisplayController.searchResultsTableView;
|
||||
// switch(type) {
|
||||
//
|
||||
// case NSFetchedResultsChangeInsert:
|
||||
// [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
|
||||
// break;
|
||||
//
|
||||
// case NSFetchedResultsChangeDelete:
|
||||
// [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
||||
// break;
|
||||
//
|
||||
// case NSFetchedResultsChangeUpdate:
|
||||
// [self configureCell:[tableView cellForRowAtIndexPath:indexPath]
|
||||
// inTableView:tableView atIndexPath:indexPath];
|
||||
// break;
|
||||
//
|
||||
// case NSFetchedResultsChangeMove:
|
||||
// [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
|
||||
// withRowAnimation:UITableViewRowAnimationFade];
|
||||
// [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
|
||||
// withRowAnimation:UITableViewRowAnimationFade];
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo
|
||||
// atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
|
||||
//
|
||||
// UITableView *tableView = self.searchDisplayController.searchResultsTableView;
|
||||
// switch(type) {
|
||||
//
|
||||
// case NSFetchedResultsChangeInsert:
|
||||
// [tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]
|
||||
// withRowAnimation:UITableViewRowAnimationFade];
|
||||
// break;
|
||||
//
|
||||
// case NSFetchedResultsChangeDelete:
|
||||
// [tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]
|
||||
// withRowAnimation:UITableViewRowAnimationFade];
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
|
||||
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
|
||||
|
||||
[self.searchDisplayController.searchResultsTableView endUpdates];
|
||||
[self.searchDisplayController.searchResultsTableView reloadData];
|
||||
// [self.searchDisplayController.searchResultsTableView endUpdates];
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
||||
|
||||
return (signed)[[self.fetchedResultsController sections] count] + ([self.query length]? 1: 0);
|
||||
NSArray *sections = [self.fetchedResultsController sections];
|
||||
NSUInteger sectionCount = [sections count];
|
||||
|
||||
if ([self.query length]) {
|
||||
__block BOOL hasExactQueryMatch = NO;
|
||||
[sections enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
id<NSFetchedResultsSectionInfo> sectionInfo = obj;
|
||||
[[sectionInfo objects] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
if ([[obj name] isEqualToString:self.query]) {
|
||||
hasExactQueryMatch = YES;
|
||||
*stop = YES;
|
||||
}
|
||||
}];
|
||||
if (hasExactQueryMatch)
|
||||
*stop = YES;
|
||||
}];
|
||||
if (!hasExactQueryMatch)
|
||||
// Add a section for "new site".
|
||||
++sectionCount;
|
||||
}
|
||||
|
||||
return (signed)sectionCount;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
|
Loading…
Reference in New Issue
Block a user