Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UISearchDisplayController结果延迟3-6秒_Ios_Uisearchbar_Parse Platform_Uisearchbardisplaycontrol - Fatal编程技术网

Ios UISearchDisplayController结果延迟3-6秒

Ios UISearchDisplayController结果延迟3-6秒,ios,uisearchbar,parse-platform,uisearchbardisplaycontrol,Ios,Uisearchbar,Parse Platform,Uisearchbardisplaycontrol,当我在搜索中输入字母时,我会延迟大约4秒,什么也做不了。其他的一切都很好。UISearchDisplayController找到我想要的,segue很好用。我不确定这是关于内存还是代码中的错误。有人能帮我吗?谢谢 我的代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object { NS

当我在搜索中输入字母时,我会延迟大约4秒,什么也做不了。其他的一切都很好。UISearchDisplayController找到我想要的,segue很好用。我不确定这是关于内存还是代码中的错误。有人能帮我吗?谢谢

我的代码

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

    NSString *uniqueIdentifier = @"MainCell";
    CustomCell3 *cell = nil;
    cell = (CustomCell3 *) [self.tableView dequeueReusableCellWithIdentifier:uniqueIdentifier];




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

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

    if (tableView == self.tableView) {
        cell.MainTitle.text = [object objectForKey:@"CountryTitle"];
        cell.DescriptTitle.text = [object objectForKey:@"DescriptTitle"];
        [cell.FlagTitle setImageWithURL:[NSURL URLWithString:[object objectForKey:@"ImaURL"]]
                       placeholderImage:[UIImage imageNamed:@"placeholder.png"]];


    };

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

        PFObject *searchedUser = [self.searchResults objectAtIndex:indexPath.row];
        NSString *content = [searchedUser objectForKey:@"CountryTitle"];
        NSString *desco = [searchedUser objectForKey:@"DescriptTitle"];
        cell.DescriptTitle.text = desco;
        cell.MainTitle.text = content;
        NSString *image = [searchedUser objectForKey:@"ImaURL"];

    [cell.FlagTitle setImageWithURL:[NSURL URLWithString:image]
                   placeholderImage:[UIImage imageNamed:@"placeholder.png"]];



        };




        return cell;
    }
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

对于每个人来说,他们都有同样的问题。我已经找到了解决办法。我重写了我所有的代码,它终于开始工作了

这是代码

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

    NSString *uniqueIdentifier = @"MainCell";
    CustomCell3 *cell = nil;
    cell = (CustomCell3 *) [self.tableView dequeueReusableCellWithIdentifier:uniqueIdentifier];




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

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

    if (tableView == self.tableView) {
        cell.MainTitle.text = [object objectForKey:@"CountryTitle"];
        cell.DescriptTitle.text = [object objectForKey:@"DescriptTitle"];
        [cell.FlagTitle setImageWithURL:[NSURL URLWithString:[object objectForKey:@"ImaURL"]]
                       placeholderImage:[UIImage imageNamed:@"placeholder.png"]];


    };

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

        PFObject *searchedUser = [self.searchResults objectAtIndex:indexPath.row];
        NSString *content = [searchedUser objectForKey:@"CountryTitle"];
        NSString *desco = [searchedUser objectForKey:@"DescriptTitle"];
        cell.DescriptTitle.text = desco;
        cell.MainTitle.text = content;
        NSString *image = [searchedUser objectForKey:@"ImaURL"];

    [cell.FlagTitle setImageWithURL:[NSURL URLWithString:image]
                   placeholderImage:[UIImage imageNamed:@"placeholder.png"]];



        };




        return cell;
    }

我想我终于知道原因了。当我搜索某个东西时,我会得到每个对象单元格1的API,所以如果我在搜索字母R中加上5个对象,它会给我6个API。当我把cancel放进去的时候,它又算我6个API了。这可能就是为什么要花这么长时间。我不知道如何减少。你的意思是什么?