在此处输入代码
查看A.
-(voID)saveImage: (UIImage*)image{ if (image != nil) { NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES); Nsstring *documentsDirectory = [paths objectAtIndex:0]; Nsstring* path = [documentsDirectory stringByAppendingPathComponent: @"iosImage.png" ]; Nsstring *filename = [path stringByAppendingFormat:email]; NSLog(@"The result of Concatenate String =%@",filename); NSData* data = UIImagePNGRepresentation(image); [data writetofile:path atomically:YES]; NSLog(@"The Path of the directory %@",path); }}
查看B.
- (UIImage*)loadImage{ NSLog(@"Email^^^^^^^^^%@",imgEmail); NSError *error; NSfileManager *fileMgr = [NSfileManager defaultManager]; NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,YES); Nsstring *documentsDirectory = [paths objectAtIndex:0]; Nsstring* path = [documentsDirectory stringByAppendingPathComponent: @"iosImage.png" ]; UIImage* image = [UIImage imageWithContentsOffile:path]; NSLog(@"documents directory: %@",[fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]); return image;}解决方法 您可以按照以下修改saveImage和loadImage函数.
-(voID)saveImage: (UIImage*)image filePath:(Nsstring*)filenameEmail{ if (image != nil) { NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,YES); Nsstring *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:filenameEmail]; NSData* data = UIImagePNGRepresentation(image); [data writetofile:filePath atomically:YES]; }}- (UIImage*)loadImage:(Nsstring*)filenameEmail{ NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,YES); Nsstring *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:filenameEmail]; UIImage *image = [[UIImage alloc] initWithContentsOffile:filePath]; return image;}
编辑:您可以获得如下特定图像.
-(UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:@"cell"]; cell.youimagevIEw.image = [self loadImage:[[yourArray indexOfObject:indexPath.row] valueForKey:@"youemailkey"]]; return cell;}
这可能对你有所帮助.
总结以上是内存溢出为你收集整理的ios – 如何在表视图单元格上加载不同的图像全部内容,希望文章能够帮你解决ios – 如何在表视图单元格上加载不同的图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)