From 941b428cfc922e8ab0fc041e7e949c284e94048f Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Sat, 12 May 2012 16:04:18 +0200 Subject: [PATCH] More reliable search results. [IMPROVED] MP-14: Made searchResultsTableView more reliable. --- External/Pearl | 2 +- .../MasterPassword (Development).xcscheme | 4 +- MasterPassword/iOS/MPSearchDelegate.m | 129 +++++++++++------- 3 files changed, 79 insertions(+), 56 deletions(-) diff --git a/External/Pearl b/External/Pearl index b45e3301..d247edba 160000 --- a/External/Pearl +++ b/External/Pearl @@ -1 +1 @@ -Subproject commit b45e33014850ece1a42afb4ac5363aadd0ea90d6 +Subproject commit d247edba08f70994bb8b0cb50413aedfa963cacd diff --git a/MasterPassword-iOS.xcodeproj/xcshareddata/xcschemes/MasterPassword (Development).xcscheme b/MasterPassword-iOS.xcodeproj/xcshareddata/xcschemes/MasterPassword (Development).xcscheme index 0d791d74..e406054d 100644 --- a/MasterPassword-iOS.xcodeproj/xcshareddata/xcschemes/MasterPassword (Development).xcscheme +++ b/MasterPassword-iOS.xcodeproj/xcshareddata/xcschemes/MasterPassword (Development).xcscheme @@ -40,8 +40,8 @@ )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)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 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 {