Note that there are some explanatory texts on larger screens.

plurals
  1. PO(iPad/iPhone) refresh a table cell while it is on screen
    text
    copied!<p>I have a table view with custom cells, each of which have images and some text which must be parsed from a webpage. I have and operation queue which gets the data from the page and calls the method <code>(void)addLoadedImageAndExcerpt:(NSString *)imgExc</code> in the tableviewcontroller after each page's data is loaded and stores the data in 2 arrays. I need each cell to refresh once the image and text that associated with it are loaded into these 2 arrays (named "articleExcerpts" and "imageDataObjects"). </p> <p>the method is as follows:</p> <pre><code>- (void)addLoadedImageAndExcerpt:(NSString *)imgExc { NSArray *imgAndExcerpt = [imgExc componentsSeparatedByString:@"{|}"]; [articleExcerpts addObject:[imgAndExcerpt objectAtIndex:1]]; NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: [imgAndExcerpt objectAtIndex:0]]]; [imageDataObjects addObject:imageData]; //count how many rows have been loaded so far. loadedCount ++; [self.table reloadData];//table is a UITableView [imageData release]; } </code></pre> <p>the problem is, I can't get the cells to change while they are on screen. Once I scroll, they show the proper data, while they are on screen, I can't get them to change. I tried the methods outlined <a href="https://stackoverflow.com/questions/1017439/refreshing-a-uitableview">here</a> and <a href="https://stackoverflow.com/questions/3577031/update-value-in-table-cell-on-iphone">here</a>, but they don't work. I tried calling <code>tableView:cellForRowAtIndexPath:</code> for the relevant row and modifying the variables, but that didn't solve anything because that method seems to create a new cell every time is is called, and doesn't get the existing ones (I'll post the code for that method further down).<br> Using <code>[self.table reloadData]</code> as I have it now doesn't seem do anything either, which really confuses me...</p> <p>my <code>tableView:cellForRowAtIndexPath:</code> method (I bet the problem is here. I'm not convinced I creating my custom cells properly) </p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CustomizedCell"; CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; for (id currentObject in topLevelObjects){ if ([currentObject isKindOfClass:[UITableViewCell class]]){ cell = (CustomCell *) currentObject; break; } } } // Configure the cell... //title cell.titleString = [titles objectAtIndex:indexPath.row]; //date cell.dateString = [dates objectAtIndex:indexPath.row]; //Photo. check if imageDataObjects array is complete up to the current row yet if (loadedCount &gt; indexPath.row) { if ([imageDataObjects objectAtIndex:indexPath.row] != @"NA") { cell.imageData = [imageDataObjects objectAtIndex:indexPath.row]; } else { cell.imageData = NULL; } } //Excerpt. check if loadedCount array is complete up to the current row yet if (loadedCount &gt; indexPath.row) { cell.exerptString = [articleExcerpts objectAtIndex:indexPath.row]; } return cell; } </code></pre> <p>what am I missing? </p>
 

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