좋은 날은 검색 항목를 표시합니다. 아래 다음과 같이reloadData
내 코드입니다 : 문제는, 내가 내 있는 viewDidLoad 내 GETSEARCH 함수를 호출 할 때, 그것을 실행하고 콜백 TITLEITEMSRETURNED을 수행합니다. 그리고 tableview는을 올바르게 다시로드합니다.
그러나 검색 창을 사용하고 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
networklayer에서 내 getBookSearch 메소드를 보여줄 수 있습니까? – wesley