내 앱에는 두 가지 구성 요소 인 UItableView와 UIButton이 있습니다.UIButton을 사용하여 UItableViewCell 내용 새로 고침
UItableViewcell은 JSON이 구현 한 원격 데이터베이스에서 데이터를로드합니다.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *TableIdentifier = @"tableidentifier"
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:TableIdentifier] autorelease];
}
NSDictionary *voc_list=[listData objectAtIndex:indexPath.row];
NSLog(@"%@",voc_list);
cell.textLabel.text = [[(NSDictionary*)voc_list objectForKey:@"vocabulary_list"]objectForKey:@"Vocabulary"];
cell.detailTextLabel.text=[[(NSDictionary*)voc_list objectForKey:@"vocabulary_list"]objectForKey:@"Translation"];
cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
return cell; }
그러나, 나는이 때 사용자 버튼을 눌러 모든 테이블 내용을 새로 고칠, 나는 다음과 같은 코드를 실행하려고 : 방금 전화하려고
-(IBAction)historyPressed:(id)sender{
isToogle = !isToogle;
if(isToogle){
// Back to original table content
}else{
// Following codes will communicate with remote server and filter data to the app.
// The app go smooth here.
NSError *error = NULL;
NSDictionary *getStuID=[NSDictionary dictionaryWithObjectsAndKeys:student_id,@"Stu_ID", nil];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:getStuID options:NSJSONWritingPrettyPrinted error:&error];
[self sendTOcompareByJSON:jsonData];
//Following codes are trying to show/refresh the data on tableview, but the app will go crash.
CGPoint location = [sender locationInView:self.table];
NSIndexPath *indexPath = [self.table indexPathForRowAtPoint:location];
UITableViewCell *new_cell=[self.table cellForRowAtIndexPath:indexPath];
historyList_= [NSArray arrayWithArray:personalized_history];
NSDictionary *dic = [historyList_ objectAtIndex:indexPath.row];
new_cell.textLabel.text=[[(NSDictionary*)dic objectForKey:@"history_list"]objectForKey:@"Vocabulary"];
new_cell.detailTextLabel.text=[[(NSDictionary*)dic objectForKey:@"history_lsit"]objectForKey:@"Score"];
}
}
테이블의 데이터 소스에 사용 된 데이터를 업데이트하고 전체 테이블을 다시로드하는 간단한 옵션이 있습니다. – ratul