0

I am currently trying to figure out why a Search Bar and Search Display Controller is not displaying results after the user provides input.

1.) I'm very confident that the delegates and everything is configured correctly

2.) I have everything set up so I can see the console NSLog the data being reutrned

3.) This does not seem to produce anything:

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
    [self.searchDisplayController.searchResultsTableView reloadData];
}

4.) Data is added to NSMutableArray but just displays blank space

Other relating questions, there appears to be blank space at the bottom of these cells, why? Furthermore, besides searchBarCancelButtonClicked is there a way to detect when the search view/mode is dismissed? I have to change the status bar colour...

Any help would be greatly appreciated.

More code:

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    NSString *authorizedSearch = [searchBar.text stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];

        NSString *post = [NSString stringWithFormat:@"search=%@",authorizedSearch];
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"blahblahblah/search.php"]]];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];
        NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
        if(conn) {
            NSLog(@"Connection Successful");
        }else{

        }


    return YES;
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data{
    NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"DATA: %@", ret);
    NSArray *objectArray=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
    [resultsJson addObject:objectArray];
    [resultsJson addObject:@"1"];
    NSLog(@"results: %@",resultsJson);
    NSLog(@"count: %i",[resultsJson count]);

}
John Doe
  • 3,559
  • 15
  • 62
  • 111

1 Answers1

0

What does your cellForRowAtIndexPath: look like?

Are you using:

[tableview dequeueReusableCellWithIdentifier:CellIdentifier];

or:

[tableview dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

Seems like there shouldn't be a difference, but I think there is.

Are you setting data properly for each backing store?


Could there be a race condition on results arriving and attempting to render them?


If you're sure the data is correct, could it be an autolayout (or similar) issue mashing up the frame? I've had that happen frequently and fix by adjusting everything in: -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath


See here for a possible reason on blank spaces at the bottom: Stop UISearchDisplayController from showing empty cells

Community
  • 1
  • 1
owenfi
  • 2,471
  • 1
  • 24
  • 37