I have an UITableView with several searchOptions (like: "Starts with", "Ends
with", etc.).
When the user changes the search option, the UISearchDisplayDelegate implements:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchScope:(NSInteger)searchOption
{
// create some data array with stuff, depending on searchOption
return YES;
}
Works fine.
But: when one scrolls in the table and then switches the searchOption the table
shows the correct items, but at some arbitrary scroll position.
So I added this line in the above method:
[ self performSelector: @selector(scrollToTop:) withObject:
controller.searchResultsTableView afterDelay: 0 ];
- (void)scrollToTop: (UITableView *)tableView
{
NSIndexPath *indexPath = [ NSIndexPath indexPathForRow: 0 inSection: 0
];
[ tableView scrollToRowAtIndexPath: indexPath atScrollPosition:
UITableViewScrollPositionTop animated: NO ];
}
Seems to be working.
But: is this the correct way?
One (minor) problem:
The UITableViewDataSource gets the message: tableView:cellForRowAtIndexPath:
first with some arbitrary rows, and then again with rows 7, 6, 5, ..., 0.
Some (small) waste of battery.
Gerriet.
P.S.
I changed searchDisplayController:shouldReloadTableForSearchScope: to return NO
and added [tableView reloadData]; to my scrollToTop: method.
No more wasted row display.
But still I am not sure whether this is the right way.
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]