I have a UITableView, contains some views in each cell, and one of the views is UIImageView. In the cellForRow method I am loading the UIImageView with an image, but sometimes, the UIImageView just shows a black screen.
I thought it can be for two reasons - Corrupted UIImage or Memory problem.
The UIImage is not corrupted (It's the same UIImage all the time), and I even checked what is the behavior when I put a manually corrupted image -> It goes white! not black...
I check if I have some memory warnings, ViewDidUnload launch -> nothing. Even simulated memory warning in the simulator, and nothing, it has nothing to do with that.
Does someone have any clue why it's happening?
Thanks!
Here is my cellForRow method. Basically, it's a list of cells with UIWebView and UIImageView on top, and when the table scrolls, I hide the webview and show the imageview, and vice versa. Maybe it has something to do with my problem, but I doubt it, cause the image is the same, and uiimagaview is not getting released.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ImMailMessage *message = [_messages objectAtIndex:indexPath.row];
ImFullMessageTableViewCell *cell = (ImFullMessageTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ImFullMessageTableViewCell"];
if (cell == nil)
{
cell = [[[NSBundle mainBundle] loadNibNamed:@"ImFullMessageTableViewCell" owner:self options:nil] objectAtIndex:0];
cell.delegate = self;
//add gestures
UIPinchGestureRecognizer *pinchGesture = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(cellPinched:)] autorelease];
[cell addGestureRecognizer:pinchGesture];
pinchGesture.delegate = self;
UIPanGestureRecognizer *panGesture = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(cellPanned:)] autorelease];
panGesture.minimumNumberOfTouches = 2;
[cell addGestureRecognizer:panGesture];
panGesture.delegate = self;
}
cell.threadState = _state;
cell.mailMessage = message;
UIImage *image = [self imageForMailMessage:message];
if (!image)
{
// if no image, put the webview and reload it.
cell.webView.mailMessage = message;
cell.webViewImageView.hidden = YES;
cell.webViewImageView.image = nil;
[cell.webView reloadMailMessage];
}
else // image exists!
{
cell.webViewImageView.image = image;
// replace the web view with the recived image.
[cell replaceWebViewWithImageView];
}
return cell;
}