Displaying images in table using HTTP 'POST' request

六眼飞鱼酱① 提交于 2019-12-24 18:12:39

问题


I am wondering how I can display the images into a table uploaded by a certain device like an "Upload History" option. I have the request retrieving the images as such...

NSString *post = [NSString stringWithFormat:@"device_code=%@", deviceCode];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://www.urlExample.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

I am retrieving the images fine I just need help putting them into the table. Anyone have an idea on how I could do that?


回答1:


You just need to render image into your custom cell using URL. You can use SDWebImage to download and stored image into cache memory.

Code to load image into your imageView:

#import <SDWebImage/SDWebImage.h>

[YOUR_IMAGE_VIEW sd_setImageWithURL:[NSURL URLWithString:YOUR_IMAGE_URL]
             placeholderImage:[UIImage imageNamed:@"placeholder.png"]];


来源:https://stackoverflow.com/questions/55641016/displaying-images-in-table-using-http-post-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!