gpt4 book ai didi

ios - 如何在 Objective-C 中将图像从主 viewController 设置到 tableView 单元格?

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

我正在用 WebService 编写程序...在主视图 Controller 中....

AppListTableViewController *appList = [self.storyboard instantiateViewControllerWithIdentifier:@"ALTVC"];

self.dataTask = [self.urlSession dataTaskWithRequest:self.urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

NSMutableDictionary *serverRes = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

NSString *imageLink = [[[[[[serverRes objectForKey:@"feed"] objectForKey:@"entry"] objectAtIndex:0] objectForKey:@"im:image"] objectAtIndex:0] objectForKey:@"label"];

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:imageLink forKey:@"image"];

[self.dataTask resume];
}

[self.navigationController pushViewController:appList animated:YES];

来自服务器的图像链接成功...但是如何在 tableView 单元格中发送和显示该图像。

在 tableView Controller 中....

cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[defaults objectForKey:@"image"]]]]; 

它不在单元格中显示任何图像...

最佳答案

在通话完成之前就向您推送 VC 的原因,请执行以下操作

self.dataTask = [self.urlSession dataTaskWithRequest:self.urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)     {

NSMutableDictionary *serverRes = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

NSString *imageLink = [[[[[[serverRes objectForKey:@"feed"] objectForKey:@"entry"] objectAtIndex:0] objectForKey:@"im:image"] objectAtIndex:0] objectForKey:@"label"];

if (imageLink)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:imageLink forKey:@"image"];
// call your navigation inside the block
AppListTableViewController *appList = [self.storyboard instantiateViewControllerWithIdentifier:@"ALTVC"];
[self.navigationController pushViewController:appList animated:YES];
}


}];

[self.dataTask resume];

关于ios - 如何在 Objective-C 中将图像从主 viewController 设置到 tableView 单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42338783/

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