在这个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
答案 0 :(得分:0)
解决!我的错误是FFQUeryOnTableView的代码并启用
[自我负责对象]
在viewdidload中..谢谢所有人!