Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing UIButton to refresh the UItableViewCell content
    text
    copied!<p>There are two components, UItableView and a UIButton, in my app.</p> <p>The UItableViewcell will load the data from remote database fulfilled by JSON.</p> <pre><code>-(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; } </code></pre> <p>However, I want to refresh all the table content when user press the button, and I try to implement the following code:</p> <pre><code> -(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:&amp;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"]; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload