검색 창에 입력하는 동안 데이터를 셀에로드해야하는 검색 창이있는 테이블 뷰가 있습니다. 내 코드는 콜백 함수를 사용해야하는 것처럼 데이터를로드합니다. 콘솔에 데이터를 인쇄하면 올바른 검색 결과가 표시되지만 reloadData 메소드가 호출 된 후 셀이 새로 고쳐지지 않습니다. 다른 문자를 입력하고 새 데이터를로드하면 이전 요청의 데이터로 테이블 뷰가 새로 고쳐집니다.두 번째 호출 이후에만 새 데이터로 테이블 뷰 새로 고침
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _teams.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TeamCell";
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
TeamModel *team = _teams[indexPath.row];
cell.textLabel.text = team.name;
return cell;
}
- (void)searchBar:(UISearchBar *)theSearchBar textDidChange:(NSString *)searchText {
NSLog(@"%@", searchText);
poolDataHandler = [[PoolDataHandler alloc] init];
[poolDataHandler GetTeams:searchText completion:^(NSArray *tempteams) {
_teams = tempteams;
NSLog(@"%@", _teams);
[self.tableView reloadData];
}];
}
JSON 결과를 구문 분석하기 위해 모델 클래스를 사용하고 있습니다.
또한 결과가 이전 쿼리보다 작 으면 행 수가 업데이트되는 것으로 보입니다. 이것에 대한 아이디어는 크게 감사하겠습니다!
업데이트 : 검색을 취소하면 초기 결과가 새로 고침됩니다. 나는 기본적인 무언가를 놓치고 있어야합니다 ...
완료 블록이 호출되는 스레드는 무엇입니까? – Wain
테이블 재로드가 블록 외부에 있어야한다고 생각합니다.이 메서드는 배열을 업데이트하기 위해 호출됩니다. – Retro
서버에서 데이터를 요청하므로 비동기 적으로 호출됩니다. 질문에 대한 대답이 – Tumtum