【问题标题】:Displaying images in table using HTTP 'POST' request使用 HTTP 'POST' 请求在表格中显示图像
【发布时间】:2019-04-11 20:54:12
【问题描述】:

我想知道如何将图像显示到某个设备上传的表格中,例如“上传历史记录”选项。我有这样的请求检索图像...

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];

我正在检索图像,我只是需要帮助将它们放入表格中。有人知道我该怎么做吗?

【问题讨论】:

  • 是的。您应该将图像下载为缩略图并将它们存储在文件夹中。然后,您可以在 UITableView 中正常显示它们。

标签: objective-c uitableview uiimageview


【解决方案1】:

您只需使用 URL 将图像呈现到您的自定义单元格中。您可以使用SDWebImage 将图像下载并存储到缓存中。

将图像加载到 imageView 的代码:

#import <SDWebImage/SDWebImage.h>

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-05
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    • 2021-12-01
    • 2013-02-03
    • 1970-01-01
    相关资源
    最近更新 更多