Refreshing the UITableView from UITableViewCell
cocoa-touch, iphone, uitableview
Solution
I did the exact thing that you're trying to do. The thing you're looking for is `needsLayout`. To wit (this is a notification observer on my UITableViewCell subclass):
- (void)reloadImage:(NSNotification *)notification
{
UIImage *image = [[SSImageManager sharedImageManager] getImage:[[notification userInfo] objectForKey:@"imageUrl"];
[self setImage:image];
[self setNeedsLayout];
}
This will pop in your image without having to reload the entire table, which can get very expensive.
Problem
Is there an easy way to trigger a [UITableView reloadData] from within a UITableViewCell? I am loading remote images to be displayed after the initial table display, and updating the image with `self.image = newImage` does not refresh the table. Resetting the cell's text value does refresh the table, but this seems sloppy. MyTableViewCell.h ``` @interface MyTableViewCell : UITableViewCell {} - (void)imageWasLoaded:(ImageData *) newImage; ``` MyTableViewCell.m ``` @implementation MyTableViewCell - (void)imageWasLoaded:(UIImage *) newImageData { self.image = newImage; //does not refresh table //would like to call [self.tableView reloadData] here, //but self.tableView does not exist. //instead I use the below line self.text = self.text; //does refresh table } @end ```