2015-02-06 209 views
0

我目前正试图找出搜索栏和搜索显示控制器在用户提供输入后不显示结果的原因。搜索栏和搜索显示控制器搜索后不显示结果

1)我非常有信心,代表和正确配置所有

2)我把一切都建立了这样我就可以看到NSLog数据被reutrned

3)控制台这似乎并没有产生什么:

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

4)数据添加到NSMutableArray但只显示空白

其他相关问题,这些单元格底部似乎有空白,为什么?此外,除了searchBarCancelButtonClicked还有一种方法可以检测搜索视图/模式何时被解散?我必须改变状态栏颜色...

任何帮助将大大赞赏。

更多代码:

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

} 
+0

发布一些源代码? – onnoweb 2015-02-06 02:43:45

+0

你想看到更多的? @onnoweb – 2015-02-06 02:44:26

回答

0

什么是你cellForRowAtIndexPath:样子?

你使用:

[tableview dequeueReusableCellWithIdentifier:CellIdentifier];

或:

[tableview dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

好像不应该有差别,但我认为是有的。

您是否为每个后备存储设置正确的数据?


在结果到达并试图渲染它们时会出现竞争条件吗?


如果你确定数据是正确的,它可能是一个自动布局(或类似)问题混搭框架?我不得不频繁发生,通过调节一切修复:对可能原因在空白底部-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath


在这里看到: Stop UISearchDisplayController from showing empty cells