在这个 TableViewController(我正在使用 Parse.com)中,我输入了所有注册用户和 SearchDisplayControll 进行研究。
现在我只有一个问题。
我看不到按字母顺序排列的注册用户的姓名……我不明白为什么。
仅当活动 searchDisplayControll 我在哪里做错时,字母顺序才有效?
谢谢大家
#import "FFRicercaUtenti.h"
#import "FFCustomCellRicercaUtenti.h"
@interface FFRicercaUtenti ()
@end
@implementation FFRicercaUtenti
@synthesize FFResultSearch;
- (void)viewDidLoad
{
[super viewDidLoad];
// [self loadObjects];
self.FFResultSearch = [NSMutableArray array];
}
-(id)initWithCoder:(NSCoder *)FFaDecoder
{
self = [super initWithCoder:FFaDecoder];
if (self) {
self.parseClassName = @"_User";
self.pullToRefreshEnabled = YES;
// self.paginationEnabled = YES;
// self.objectsPerPage = 10;
}
return self;
}
-(PFQuery *)FFQUeryOnTableView {
PFQuery *query = [PFUser query ];
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if (self.objects.count == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
[query orderByDescending:@"Nome_Cognome"];
return query;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait ||(interfaceOrientation));
}
- (void)callbackLoadObjectsFromParse:(NSArray *)result error:(NSError *)error {
if (!error) {
[self.FFResultSearch removeAllObjects];
NSLog(@"Successfully fetched %d entries", result.count);
[self.FFResultSearch addObjectsFromArray:result];
[self.searchDisplayController.searchResultsTableView reloadData];
} else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}
-(void)filterResults:(NSString *)searchTerm {
[self.FFResultSearch removeAllObjects];
PFQuery *query = [PFUser query];
[query orderByAscending:FF_USER_NOMECOGNOME];
[query whereKey:FF_USER_NOMECOGNOME containsString:searchTerm];
query.cachePolicy = kPFCachePolicyNetworkOnly;
[query findObjectsInBackgroundWithTarget:self selector:@selector(callbackLoadObjectsFromParse:error:)];
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
[self filterResults:searchString];
return YES;
}
- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
{
tableView.rowHeight = 65.0f; // or some other height
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == self.tableView) {
return self.objects.count;
} else {
return self.FFResultSearch.count;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
} else {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
FFCustomCellRicercaUtenti *cell = (FFCustomCellRicercaUtenti * )[self.tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell) {
cell = [[FFCustomCellRicercaUtenti alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"UFFCustomDisclosure"]];
if (tableView == self.tableView) {
cell.FF_UsernameLabel.text = [object objectForKey:FF_USER_NOMECOGNOME];
cell.FF_FotoProfilo.image = [UIImage imageNamed:@"FFIMG_Camera"];
PFFile *imageFile = [object objectForKey:FF_USER_FOTOPROFILO];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
cell.FF_FotoProfilo.image =[UIImage imageWithData:data]; }];
}
else if(tableView == self.searchDisplayController.searchResultsTableView) {
PFObject *searchedUser = [self.FFResultSearch objectAtIndex:indexPath.row];
NSString *content = [searchedUser objectForKey:FF_USER_NOMECOGNOME];
cell.FF_UsernameLabel.text = content;
cell.FF_FotoProfilo.image = [UIImage imageNamed:@"FFIMG_Camera"];
PFFile *imageFile = [searchedUser objectForKey:FF_USER_FOTOPROFILO];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
cell.FF_FotoProfilo.image =[UIImage imageWithData:data]; }];
NSLog(@"Content: %@", content);
}
return cell;
}
@end