2
0

More reliable search results.

[IMPROVED]  MP-14: Made searchResultsTableView more reliable.
This commit is contained in:
Maarten Billemont 2012-05-12 16:04:18 +02:00
parent 0d638a4c3f
commit 941b428cfc
3 changed files with 79 additions and 56 deletions

2
External/Pearl vendored

@ -1 +1 @@
Subproject commit b45e33014850ece1a42afb4ac5363aadd0ea90d6 Subproject commit d247edba08f70994bb8b0cb50413aedfa963cacd

View File

@ -40,8 +40,8 @@
</MacroExpansion> </MacroExpansion>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug" buildConfiguration = "Debug"

View File

@ -125,66 +125,89 @@
[self.searchDisplayController.searchResultsTableView reloadData]; [self.searchDisplayController.searchResultsTableView reloadData];
} }
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { // See MP-14, also crashes easily on internal assertions etc..
//- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
[self.searchDisplayController.searchResultsTableView beginUpdates]; //
} // [self.searchDisplayController.searchResultsTableView beginUpdates];
//}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject //
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { //- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
// atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
UITableView *tableView = self.searchDisplayController.searchResultsTableView; //
switch(type) { // UITableView *tableView = self.searchDisplayController.searchResultsTableView;
// switch(type) {
case NSFetchedResultsChangeInsert: //
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; // case NSFetchedResultsChangeInsert:
break; // [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
// break;
case NSFetchedResultsChangeDelete: //
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; // case NSFetchedResultsChangeDelete:
break; // [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
// break;
case NSFetchedResultsChangeUpdate: //
[self configureCell:[tableView cellForRowAtIndexPath:indexPath] // case NSFetchedResultsChangeUpdate:
inTableView:tableView atIndexPath:indexPath]; // [self configureCell:[tableView cellForRowAtIndexPath:indexPath]
break; // inTableView:tableView atIndexPath:indexPath];
// break;
case NSFetchedResultsChangeMove: //
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] // case NSFetchedResultsChangeMove:
withRowAnimation:UITableViewRowAnimationFade]; // [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] // withRowAnimation:UITableViewRowAnimationFade];
withRowAnimation:UITableViewRowAnimationFade]; // [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
break; // withRowAnimation:UITableViewRowAnimationFade];
} // break;
} // }
//}
//
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo //
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type { //- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo
// atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
UITableView *tableView = self.searchDisplayController.searchResultsTableView; //
switch(type) { // UITableView *tableView = self.searchDisplayController.searchResultsTableView;
// switch(type) {
case NSFetchedResultsChangeInsert: //
[tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] // case NSFetchedResultsChangeInsert:
withRowAnimation:UITableViewRowAnimationFade]; // [tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]
break; // withRowAnimation:UITableViewRowAnimationFade];
// break;
case NSFetchedResultsChangeDelete: //
[tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] // case NSFetchedResultsChangeDelete:
withRowAnimation:UITableViewRowAnimationFade]; // [tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]
break; // withRowAnimation:UITableViewRowAnimationFade];
} // break;
} // }
//}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[self.searchDisplayController.searchResultsTableView endUpdates]; [self.searchDisplayController.searchResultsTableView reloadData];
// [self.searchDisplayController.searchResultsTableView endUpdates];
} }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - (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 { - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {