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]);
}