0

私のアプリには、UItableView と UIButton の 2 つのコンポーネントがあります。

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"];


    }


    }
4

2 に答える 2

0

からデータを取得する方法がわかりません[self sendTOcompareByJSON:jsonData];。Webサーバーへの同期呼び出しの場合、この直後にデータソースを更新できます(この場合は、を使用してテーブルビューを埋めていますlistData) .したがってlistData、新しいコンテンツで更新されたら、このようにテーブルビューをリロードする必要があります[self.table reloadData]

Web サーバーへの非同期呼び出しの場合は、データソースを更新し、コールバックでテーブルをリロードします。

お役に立てれば。

于 2013-08-29T07:18:17.477 に答える