iphone - images in custom table view not showing in the right order -


i have app loads images in array database after array generate new array thumbnail images images array, use sql data sorted db, when app loads , log images , thumbnail array both sorted ok, problem thumbnail images in tableview not sorted in same order of thumbnail array.

here code

php code getting data sorted :

$result = mysql_query("select * $tablename user = '$u' order id desc"); 

then xcode code

- (void)viewdidload {     username = [savedstock objectforkey:@"username"];      //========load array server=============\\      nsstring *strurl = [nsstring stringwithformat:@"%@load.php?username=%@", sitehost,username];      nsdata *dataurl = [nsdata datawithcontentsofurl:[nsurl urlwithstring:strurl]];      // receive returend value     nsstring *strresult = [[nsstring alloc] initwithdata:dataurl encoding:nsutf8stringencoding];      temparray = [strresult componentsseparatedbystring:@"+-+"];      nsstring *tempurl = [temparray objectatindex:0];     nsstring *tempdec = [temparray objectatindex:1];     nsstring *temptime = [temparray objectatindex:2];     nsstring *tempdate = [temparray objectatindex:3];      temparrayurl = [tempurl componentsseparatedbystring:@"/u/"];     array = [[nsmutablearray alloc] initwitharray:temparrayurl];      temparraytime = [temptime componentsseparatedbystring:@"/t/"];     arraytime = [[nsmutablearray alloc] initwitharray:temparraytime];      temparraydate = [tempdate componentsseparatedbystring:@"/d/"];     arraydate = [[nsmutablearray alloc] initwitharray:temparraydate];      temparraydesc = [tempdec componentsseparatedbystring:@"/r/"];     arraydesc = [[nsmutablearray alloc] initwitharray:temparraydesc];      number = [array count] - 1;      arraythumbs = [[nsmutablearray alloc] init];      (int = 0; i<number; i++) {         nsstring *tempstring = [array objectatindex:i];         nsstring *lasturl = [tempstring substringfromindex:[tempstring length]-14];         nsstring *thumb = [lasturl substringtoindex:[lasturl length]-4];         nsstring *newlast = [thumb stringbyappendingstring:@"_thumb.jpg"];         nsstring *firsturl = [tempstring substringtoindex:[tempstring length]-14];         nsstring *addone = [firsturl stringbyappendingstring:@"thumb/"];         nsstring *newurl = [addone stringbyappendingstring:newlast];         [arraythumbs addobject:newurl];     }      [arraythumbs addobject:@""];      nslog(@"%@",array);     nslog(@"%@",arraythumbs);  } 

loading in table view :

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {  static nsstring *cellidentifier = @"customcell";  customcell *cell = (customcell *) [tableview dequeuereusablecellwithidentifier:cellidentifier];  if (cell == nil) {     nsarray *toplevelobjects = [[nsbundle mainbundle] loadnibnamed:@"customcell" owner:self options:nil];     (id currentobject in toplevelobjects) {         if ([currentobject iskindofclass:[customcell class]]) {             cell = (customcell *) currentobject;             break;         }     }              //using code here load thumbnail images misses order else ok     nsstring *tempstring = [arraythumbs objectatindex:indexpath.row];     nsurl *imageurl = [nsurl urlwithstring:tempstring];     nsdata *imagedata = [nsdata datawithcontentsofurl:imageurl];     uiimage *image = [uiimage imagewithdata:imagedata];     cell.img.image = image;  }  uiimage *cellimage = [uiimage imagenamed:@"customcell.png"]; uiimageview *cellbackgroundimage = [[uiimageview alloc]initwithimage:cellimage]; cell.backgroundview = cellbackgroundimage;  cell.selectedbackgroundview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"customcellselected.png"]];  //using here load thumbnail tableview freeze when scroll  //    nsstring *tempstring = [arraythumbs objectatindex:indexpath.row]; //    nsurl *imageurl = [nsurl urlwithstring:tempstring]; //    nsdata *imagedata = [nsdata datawithcontentsofurl:imageurl]; //    uiimage *image = [uiimage imagewithdata:imagedata]; //    cell.img.image = image;  cell.url.text = [array objectatindex:indexpath.row]; cell.time.text = [arraytime objectatindex:indexpath.row];     cell.date.text = [arraydate objectatindex:indexpath.row]; cell.des.text = [arraydesc objectatindex:indexpath.row];  cell.url.textcolor = [uicolor whitecolor]; cell.time.textcolor = [uicolor whitecolor]; cell.date.textcolor = [uicolor whitecolor]; cell.des.textcolor = [uicolor whitecolor];  return cell; } 

**notice when change thumbnail images code place works fine freeze tableview when scrolling

and log both arrays

2013-08-16 07:04:29.367 img[12575:c07] ( "http://localhost/img/i/yzrlnucfmr.jpg", "http://localhost/img/i/43bxpwheqg.jpg", "http://localhost/img/i/qeuprbsbfx.jpg", "http://localhost/img/i/zds0q5aosx.jpg", "http://localhost/img/i/ebfo8a9gn5.jpg", "http://localhost/img/i/oaszbydmqm.jpg", "http://localhost/img/i/dd5szyltqv.jpg", "http://localhost/img/i/rblzbcn0cd.jpg", "" ) 2013-08-16 07:04:29.367 img[12575:c07] (     "http://localhost/img/i/thumb/yzrlnucfmr_thumb.jpg",     "http://localhost/img/i/thumb/43bxpwheqg_thumb.jpg",     "http://localhost/img/i/thumb/qeuprbsbfx_thumb.jpg",     "http://localhost/img/i/thumb/zds0q5aosx_thumb.jpg",     "http://localhost/img/i/thumb/ebfo8a9gn5_thumb.jpg",     "http://localhost/img/i/thumb/oaszbydmqm_thumb.jpg",     "http://localhost/img/i/thumb/dd5szyltqv_thumb.jpg",     "http://localhost/img/i/thumb/rblzbcn0cd_thumb.jpg",     "" ) 

any idea ? :)

i suggest use sdwebimage framework lazy loading images in table view.

sdwebimage asynchronous image downloader cache support uiimageview category.

this library provides category uiimageview support remote images coming server.

sample code

[cell.imageview setimagewithurl:[nsurl urlwithstring:@"http://www.domain.com/path/to/image.jpg"]                    placeholderimage:[uiimage imagenamed:@"placeholder.png"]]; 

here can provide placeholder image displayed until server image ready displayed.

the issue facing because have kept image loading code in if condition why getting weird issue.

if (cell == nil) { ... } if condition true if no cell reused. , want reuse cells. configure them when have valid cell.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -