gpt4 book ai didi

ios - 使用 Nsurlconnection Post 方法不显示图像

转载 作者:行者123 更新时间:2023-11-29 01:01:52 25 4
gpt4 key购买 nike

nslog using json我正在使用 nsurlconnectionPOST方法并为“查看”、“购买”、“更新”、“图像”创建了四个数组。显示在 tableviewcell 中但“图像”没有显示。 “png 格式的 url”中的图像。

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{


NSError* error;
json = [NSJSONSerialization JSONObjectWithData: mutableData
options:kNilOptions
error:&error];
NSLog(@"%@",json);
sellArray = [json valueForKeyPath:@"BranchByList.sell"];
buyArray = [json valueForKeyPath:@"BranchByList.buy"];
updataedArray = [json valueForKeyPath:@"BranchByList.updated"];
imageArray = [json valueForKeyPath:@"BranchByList.flag_image"];

[_datad reloadData];
}

tableview 委托(delegate)方法是:

-(NSInteger)numberOfSectionsInTableView:(UITableView *) tableView{

return 1;
}

-(NSInteger)tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section{
return [sellArray count];
return [buyArray count];
return [updataedArray count];
return [imageArray count];

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"path" forIndexPath:indexPath];
cell.sellbl.text=[sellArray objectAtIndex:indexPath.row];
cell.buylbl.text=[buyArray objectAtIndex:indexPath.row];
cell.updatedlbl.text = [updataedArray objectAtIndex:indexPath.row];
cell.imglbl.image = [UIImage imageNamed:[imageArray objectAtIndex:indexPath.row]];
return cell;
}

-(void)tableView: (UITableView *) tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
}

最佳答案

你是直接给图片分配url!那根本行不通。您需要先将url添加到NSUrl,然后使用NSData将url转换为数据,然后将数据分配给图像。

要完成它,请在您的代码中添加以下代码行:

NSURL *url = [NSURL URLWithString:[imageArray objectAtIndex:indexPath.row]];

NSData *data = [NSData dataWithContentsOfURL:url];

cell.imglbl.image = [UIImage imageWithData:data];

我再发布一个示例以加深理解。我有一个 url,我需要将该 url 中的图像显示到我的设备。对于那个 m 使用下面的代码行:

NSURL *url = [NSURL URLWithString:@"http://1.bp.blogspot.com/-9yd6LPL2N6U/VatsUdMffPI/AAAAAAAAAl4/Pq1S6Q20fy0/s1600/hello_world.gif"];

NSData *data = [NSData dataWithContentsOfURL:url];

_imgView.image=[UIImage imageWithData:data];

上面的 url 只是从 google 获取的图片的随机 url。

结果:

enter image description here

关于ios - 使用 Nsurlconnection Post 方法不显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36911506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com