저는이 문제로 많은 어려움을 겪고 있습니다. 일부 게시물은이 문제를 다루지 만 내 경우에는 해결책이 없습니다.UISearchController 테이블 뷰 결과가 비어 있습니다.
여기에 문제가 있습니다. UISearchController 메서드로 일부 결과를 표시하고 싶습니다. 사용자 정의 셀이있는 원래의 테이블보기는 모든 항목이 여기에 있으며 원하는대로 표시한다는 의미에서 완벽하게 작동합니다.
범위 막대가있는 검색 창을 사용하면 다시 모든 것이 완벽하게 작동하고 필터링 된 결과가 목록에 올바르게 저장되며 사용자 지정 셀조차도 필요한 모든 것을 얻습니다. 즉 셀을 확인할 때 속성, 그것은 필터링 된 항목에 해당합니다 ...
하지만 내가 어디가는 "새로운"테이블보기 (결과와 함께 하나)가 비어 있다는 의미에서 모든보기가 가득 차 있습니다 빈 줄과 함께) 필터링 된 항목이 여기에 있고 cellForRowAtIndexPath가 (적어도 표시 될 때까지) 작업을 수행하고 있음에도 불구하고.
누군가이를 해결할 수 있도록 도와 줄 수 있습니까?
코드 : 난 당신이 더 많은 코드를 필요로
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController {
NSPredicate *predicate;
NSString *searchText = searchController.searchBar.text;
NSInteger scope = searchController.searchBar.selectedScopeButtonIndex;
if (scope == 0) {
predicate = [NSPredicate predicateWithFormat:@"SELF.drugName contains[c] %@", searchText];
}
if (scope == 1) {
predicate = [NSPredicate predicateWithFormat:@"SELF.marque contains[c] %@", searchText];
}
else if (scope == 2) {
predicate = [NSPredicate predicateWithFormat:@"SELF.classFamily contains[c] %@", searchText];
}
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:[[[SubstrateStore sharedStore] allSubstrates] filteredArrayUsingPredicate:predicate]];
self.filteredResults = [NSMutableArray arrayWithArray:tempArray];
[self.tableView reloadData]; // -> I tried to remove, to change the table view, etc, it does change anything
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:kCellIdentifier forIndexPath:indexPath];
Substrate *substrate = self.products[indexPath.row];
if (_searchController.active && ![_searchController.searchBar.text isEqualToString:@""]) {
substrate = self.filteredResults[indexPath.row];
}
[self configureCell:cell forProduct:substrate]; // when I check cell attributes (drugName,...), they are there...
return cell; // it works when no search is done (with the native table view) but the cell is not displayed when using the search bar (empty table view)
}
...
감사합니다!
1인가 도움이되는 경우? 2.'self.filteredResults'가'self.tableView'의 올바른 데이터 소스인지 확신합니까? 3.'[self.tableView reloadData]'를 호출하면,'UITableViewDelegate' 메소드가 호출됩니까? – Ryan
proble은 결과 테이블 뷰 – Trichophyton