ios - Image on UITableView Cell -
i have different folder on document directory , have images on each folder. want display 1 image different folder. have tried program crashe @ line.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } //i dont know put here display sqlite nsuinteger row = [indexpath row]; cell.textlabel.text = [array1 objectatindex:row]; //cell.detailtextlabel.text = [array2 objectatindex:row]; nsstring *b = [array2 objectatindex:row]; nslog(@"b=%@",b); nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nslog(@"%@",paths); nsstring *documentsdirectory = [paths objectatindex:0]; nserror *error = nil; nsarray *imagefilenames = [[nsfilemanager defaultmanager] contentsofdirectoryatpath:[documentsdirectory stringbyappendingpathcomponent:[nsstring stringwithformat:@"%@",b]] error:&error]; nslog(@"file=%@",imagefilenames); nsmutablearray *images = [[nsmutablearray alloc ] init]; (int = 0; < [imagefilenames count]; i++) { nsstring *getimagepath = [documentsdirectory stringbyappendingpathcomponent:[nsstring stringwithformat:@"%@/%d.png",b, i]]; uiimage *img = [uiimage imagewithcontentsoffile:getimagepath]; [images addobject:img]; nslog(@"%@",getimagepath); } nslog(@"images=%@",images); cell.imageview.image=[imagefilenames objectatindex:0]; //nslog(@"row=%u",row); return cell; }
you can directly use [uiimage imagenamed:@""]
images rather imagewithcontentsoffile
Comments
Post a Comment