0

検索に文字を入力すると、約 4 秒間ラグが発生し、何もできません。他のすべてはうまくいきます。UISearchDisplayController は、私が欲しいものを見つけてくれます。セグエはうまく機能します。それがメモリに関するものなのか、コードの間違いによるものなのかはわかりません。誰でも私を助けることができますか?ありがとう

私のコード

TableViewController.m

@implementation TableViewController

@synthesize colorsTable;
@synthesize searchBar;
@synthesize searchController;
@synthesize searchResults;

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showDetail"]) {
        {
            DetailViewController *sdvc = (DetailViewController *)[segue destinationViewController];


            if(self.searchDisplayController.active) {
                NSIndexPath *indexPath = [[self tableView] indexPathForSelectedRow];
                PFObject *object = [self.objects objectAtIndex:indexPath.row];

                object = (PFObject *)[[self searchResults]objectAtIndex:[[[[self searchDisplayController]searchResultsTableView]indexPathForSelectedRow]row]];
                sdvc.detailItem = object;

            }   else {

                NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
                PFObject *object = [self.objects objectAtIndex:indexPath.row];
                DetailViewController *detailViewController = [segue destinationViewController];
                detailViewController.detailItem = object;


            }

        } 
    }
}


- (void)viewDidLoad
{
    [super viewDidLoad];

    [self performSelector:@selector(runThisMethod) withObject:nil afterDelay:1.9f];
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];

    self.tableView.tableHeaderView = self.searchBar;

    self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];

    self.searchController.searchResultsDataSource = self;
    self.searchController.searchResultsDelegate = self;
    self.searchController.delegate = self;


    CGPoint offset = CGPointMake(0, self.searchBar.frame.size.height);
    self.tableView.contentOffset = offset;

    self.searchResults = [NSMutableArray array];



-(void)filterResults:(NSString *)searchTerm {

    [self.searchResults removeAllObjects];

    PFQuery *query = [PFQuery queryWithClassName: self.parseClassName];
    [query whereKeyExists:@"MestoName"];  //this is based on whatever query you are trying to accomplish
    [query whereKey:@"MestoName" containsString:searchTerm];

    NSArray *results  = [query findObjects];

    NSLog(@"%@", results);
    NSLog(@"%u", results.count);

    [self.searchResults addObjectsFromArray:results];
}


- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
    [self filterResults:searchString];
    return YES;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    if (tableView == self.tableView) {
        //if (tableView == self.searchDisplayController.searchResultsTableView) {

        return self.objects.count;

    } else {

        return self.searchResults.count;

    }

}
- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
{
    tableView.rowHeight = 90.0f;
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {

    static NSString *uniqueIdentifier = @"colorsCell";

    CustomCell *cell = nil;

    cell = (CustomCell *) [self.tableView dequeueReusableCellWithIdentifier:uniqueIdentifier];


    [cell.imagevieww setImageWithURL:[NSURL URLWithString:[object objectForKey:@"ImageURL"]]
                    placeholderImage:[UIImage imageNamed:@"placeholder.png"]];


    cell.cellTitle.text = [object objectForKey:@"MestoName"];
    cell.cellDescript.text = [object objectForKey:@"MestoSubname"];


    if (!cell) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"colorsCell" owner:nil options:nil];

        for (id currentObject in topLevelObjects)
        {
            if([currentObject isKindOfClass:[CustomCell class]])
            {
                cell = (CustomCell *)currentObject;
                break;
            }
        }
    }


        if (tableView == self.tableView) {
            cell.cellTitle.text = [object objectForKey:@"MestoName"];
        } else {

            PFUser *obj2 = [self.searchResults objectAtIndex:indexPath.row];
            PFQuery *query = [PFQuery queryWithClassName:@"Mesta"];
            PFObject *searchedUser = [query getObjectWithId:obj2.objectId];

            NSString *boottext = [searchedUser objectForKey:@"MestoName"];
            cell.cellTitle.text = boottext;

            NSString *bootsubtext = [searchedUser objectForKey:@"MestoSubname"];
            cell.cellDescript.text = bootsubtext;

            NSString *bootimage = [searchedUser objectForKey:@"ImageURL"];
            [cell.imagevieww setImageWithURL:[NSURL URLWithString:bootimage]];


            NSLog(@"Content: %@", boottext);

        }
            return cell;

        }



@end
4

1 に答える 1