2013-09-25 34 views
0

在這個TableViewController(我正在使用Parse.com)我輸入了所有註冊用戶和SearchDisplayControll進行研究。PFQuery order by不顯示PFQueryTableViewController

現在我只有一個問題。

我看不到按字母順序排列的註冊用戶名......我不明白爲什麼。

字母順序只適用於活動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 

回答

0

解決了!我的錯誤是在FFQUeryOnTableView代碼,使

[自我加載對象]

在viewDidLoad中..Thanks所有!