2015-02-06 131 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