objective c - SDWebImage not showing randomly in UITableViewCell -
hello have script downloads image , dynamically sets uitableview height after finishes download, images randomly not show , curious think when change , forth tab images appear . in options argument passing sdwebimageretryfailed.
any idea more welcome , thanks.
@interface neobuggyfrontpageviewcontroller() { uiimageview *adbanner; nsarray *news ; nsmutabledata *imagedata; nsurlconnection *connection; uiimage *neoimage; nsstring *category; rssitem *item; frontpageviewnewscell *cell ; cgrect newframe; __block cgrect descframe; float newwidth , newheight; __block float blockheight; } -(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { item = [news objectatindex:[indexpath row]]; cell = [tableview dequeuereusablecellwithidentifier:@"frontpagenewscell"]; [[cell newstitle] settext:[item title]]; [[cell newsvideo] setalpha:0.0]; if ([item newsimageurl]){ descframe = [[cell newsbody] frame]; [[cell newsimage] setimagewithurl:[item newsimageurl] placeholderimage:[uiimage imagenamed:@"placeholderimage.png"] options:sdwebimageretryfailed completed:^(uiimage *image, nserror *error, sdimagecachetype cachetype){ if (image) { cgrect newsimageframe = [[cell newsimage] frame]; float downimagewidth = image.size.width; float downimageheight = image.size.height; float newsimagewidth = 304.00; //imageviewsize.size.width; if (downimagewidth > newsimagewidth) { float scalefactor = newsimagewidth / downimagewidth; newwidth = downimagewidth * scalefactor; newheight = downimageheight * scalefactor; } else { newwidth = downimagewidth; newheight = downimageheight; } newframe = cgrectmake(newsimageframe.origin.x, newsimageframe.origin.y, newwidth, newheight); [[cell newsimage] setframe:newframe]; //asigno el nuevo frame la imagen . float neworiginy = newframe.origin.y + newframe.size.height + 10.00; descframe = cgrectmake(cell.newsbody.frame.origin.x, neworiginy, 304.00, cell.newsbody.frame.size.height); blockheight = newheight; } nslog(@"image %@ cached ? %u", image ,cachetype); if (error) { nslog(@"error: %@",error); } }]; } else if([item newsvideourl]) { [[cell newsimage] setalpha:0.0]; [[cell newsvideo] setalpha:1.0]; [[cell newsvideo] loadrequest:[nsurlrequest requestwithurl:[item newsvideourl]]]; float neworiginy = cell.newsvideo.frame.origin.y + cell.newsvideo.frame.size.height + 10.00; descframe = cgrectmake(cell.newsbody.frame.origin.x, neworiginy, 304, cell.newsbody.frame.size.height); blockheight = cell.newsvideo.frame.size.height; } [[cell newsimage] setneedsdisplay]; nsstring *desc = [[nsstring alloc] initwithstring:[item description]]; [[cell newsbody] setframe:descframe]; desc = [desc htmltostring:desc]; [[cell newsbody] settext:desc]; [[cell newsbody] setnumberoflines:0]; [[cell newsbody] sizetofit]; [cell setselectionstyle:uitableviewcellselectionstylenone]; return cell; } -(cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { cell = (frontpageviewnewscell *)[self tableview:tableview cellforrowatindexpath:indexpath]; cgsize descheight = [[[cell newsbody] text] sizewithfont:[[cell newsbody] font] constrainedtosize:cell.newsbody.frame.size linebreakmode:[[cell newsbody] linebreakmode]]; cgsize titleheight = [[[cell newstitle] text] sizewithfont:[[cell newstitle] font] constrainedtosize:cell.newstitle.frame.size linebreakmode:[[cell newstitle] linebreakmode]]; newheight = cell.newsimage.frame.size.height; if (blockheight == 0) { [tableview reloaddata]; } else { float ch = titleheight.height + blockheight + descheight.height + 70; [self setcellheight:ch]; } return _cellheight; }
partially solved although solution less ideal. since needed show 10 cells prevented reuse of uitableviewcell
-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { item = [news objectatindex:[indexpath row]]; nsstring *identifier = [nsstring stringwithformat:@"cell %d", indexpath.row]; uinib *nib = [uinib nibwithnibname:@"frontpageviewnewscell" bundle:nil]; [[self tableview] registernib:nib forcellreuseidentifier:identifier]; cell = [tableview dequeuereusablecellwithidentifier:identifier]; // cell = [tableview dequeuereusablecellwithidentifier:@"frontpagenewscell"];
still interested in finding solution reusing cell
thanks,
Comments
Post a Comment