Question

in this TableViewController (I'm working with Parse.com) I entered all registered users and SearchDisplayControll for research.

Now I have only one problem .

I can not see in alphabetical order, the names of registered users ... I do not understand why.

The alphabetical order only works when the active searchDisplayControll where am I doing wrong?

Thanks to all

#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
Was it helpful?

Solution

Solved! My error is the code for the FFQUeryOnTableView and enable

[self loadobject]

in viewdidload ..Thanks for all!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top