i new mobile development. in application i've got table shows recipes created user. cell designed nib-file image (which asynchronously loaded) , 2 labels. seems ok on simulator. scrolling through table looks horrible on real device after implementation of asynchronous loading of images. while using time profiler of time occupied main function. i'm thinking whether may caused using core data. i'm not sure this. grateful if me issue.
this how fill cell data:
-(uitableviewcell*)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{ static nsstring *identifier = @"tablecell"; simpletableviewcell *cell = (simpletableviewcell *)[self.tableview dequeuereusablecellwithidentifier:identifier]; if (cell == nil) { nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"tablecell" owner:self options:nil]; cell = [nib objectatindex:0]; } receipe *cellrecipe = [self.fetchedresultscontroller objectatindexpath:indexpath]; cell.recipename.text = cellrecipe.name; nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *path = [documentsdirectory stringbyappendingpathcomponent:cellrecipe.image]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ uiimage *image = [uiimage imagewithcontentsoffile:path]; dispatch_async(dispatch_get_main_queue(), ^{ [cell.recipeimage setimage:image]; }); }); cell.recipedetails.text = cellrecipe.ingredients; uiimage *favourite; if ([cellrecipe.isfavourite boolvalue] == yes) { favourite = [uiimage imagenamed:@"liked.png"]; } [cell.recipeisfavouritebutton setimage:favourite forstate:uicontrolstatenormal]; favourite = nil; return cell; }
use
[tableview dequeuereusablecellwithreuseidentifier:identifier forindexpath:indexpath]; instead of
[tableview dequeuereusablecellwithidentifier:identifier]; i think there no need asynchronous loading, use normal loading.
Comments
Post a Comment