Ich versuche, UIImagages vom Server asynchron in UITableViewCell zu laden. Mein Code funktionierte im Simulator, aber nicht auf dem Gerät. Mein Code wie folgt,UImage funktioniert nicht richtig?
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
IScopeCustomTableCell *cell = (IScopeCustomTableCell *)[tableView dequeueReusableCellWithIdentifier:CellClassName];
if (!cell){
NSArray *topLevelItems = [cellLoader instantiateWithOwner:self options:nil];
cell = [topLevelItems objectAtIndex:0];
}
cell.delegate = self;
cell.videoTitle.text = [[videoDataArray objectAtIndex:indexPath.row] objectForKey:@"VideoTitle"];
cell.videoLink = [[videoDataArray objectAtIndex:indexPath.row] objectForKey:@"VideoLink"];
cell.videoThumbnailImageLink = [[videoDataArray objectAtIndex:indexPath.row] objectForKey:@"VideoThumbnail"];
cell.videoThumbnail.tag = indexPath.row;
cell.tag = indexPath.row;
[cell.activityIndicator startAnimating];
NSInvocationOperation *operation = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(loadImage:)
object:cell];
[queue addOperation:operation];
return cell;
}
- (void)loadImage:(IScopeCustomTableCell *)cell {
NSLog(@"Image link :- %@", cell.videoThumbnailImageLink);
//NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:cell.videoThumbnailImageLink]];
NSData* imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:cell.videoThumbnailImageLink]];
UIImage* image = [UIImage imageWithData:imageData];
cell.videoThumbnail.image = image;
[cell.activityIndicator stopAnimating];
[cell.activityIndicator removeFromSuperview];
//[self performSelectorOnMainThread:@selector(displayImage:) withObject:image waitUntilDone:NO];
}
Der obige Code Geldbusse Simulator, aber nicht auf dem Gerät, becoz, UIImage * Bild get (0X0) null in obwohl NSData loadimage Verfahren geeignete Daten enthalten.
howmany mb der Dateigröße vom Server kommen ??? – parag
@paragkavar, 20KB – Tirth
Entschuldigung für die Angabe der offensichtlichen, aber Sie haben bereits überprüft, dass Ihr Gerät Zugriff auf das Internet hat, nicht wahr? Außerdem ist das Abfeuern eines Threads bei jeder Anzeige der Zelle nicht die beste Lösung. Sie können viele Tutorials im Web finden, um Bilder asynchron zu laden. – Leonardo