Добрый день,reloadData не работает (называемые в делегатом)
Я использую UITableViewController для отображения поиска предметов.
Мой код выглядит следующим образом ниже: Проблема заключается в том, когда я называю GETSEARCH функцию в моей viewDidLoad, он работает и выполняет функцию обратного вызова TITLEITEMSRETURNED. И таблица стола правильно загружает.
Однако, если я использую поисковую панель и выполните GETSEARCH. делегат вызывается, данные загружаются в массив правильно, но tableView никогда не обновляется.
Однако, если я нажму кнопку серого креста, таблица внезапно обновится !!? Что дает?
-(void)TitleItemsReturned:(NSArray*)titleItems{
for(TitleItem* titleItem in titleItems){
// NSLog(@"TITLE: %@ ISBN: %@",titleItem.Title,titleItem.ISBN);
[searchResults addObject:titleItem];
}
[self.tableView reloadData];
}
- (void)viewDidLoad
{
NSLog(@"RUN");
networkLayer=[[NLBNetworkLayer alloc]init];
searchResults=[[NSMutableArray alloc]initWithCapacity:500];
// [networkLayer getBookSearch:TITLE term:@"Inferno"];
[super viewDidLoad];
}
-(void)viewDidAppear:(BOOL)animated{
[networkLayer setDelegate:(id)self];
}
#pragma mark - Table view data source
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
TitleItem *titleItem = nil;
titleItem = [searchResults objectAtIndex:indexPath.row];
// Configure the cell
cell.textLabel.text = titleItem.Title;
NSLog(@"called %@",titleItem.Title);
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"count %d",[searchResults count]);
return [searchResults count];
}
#pragma mark - UISearchDisplayController Delegate Methods
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
return YES;
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
//[networkLayer getBookSearch:TITLE term:searchBar.text];
[networkLayer getBookSearch:TITLE term:@"Inferno"];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
NSLog(@"all removed");
[searchResults removeAllObjects];
[self.tableView reloadData];
}
Вы уверены, что после поиска завершена перезагрузка таблицы? – Ganapathy
Можете ли вы показать мне ваш метод getBookSearch в сетевом сервере? – wesley