我正在尝试将我的UITableView中显示的图像传递给我的细节UITableView。我的tableview中的图像是从JSON端点提取的。知道我怎么能这样做吗?目前,这是我的应用程序崩溃的一行:
featureImage.image = [[articleDetail objectForKey:@“Image”] objectForKey:@“filename”];
知道我怎么能这样做吗?请参阅下面的代码。
TableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
FullArticleViewController *detailViewController = [[FullArticleViewController alloc]
initWithNibName:@"FullArticleViewController" bundle:nil];
detailViewController.title = [[Doctors objectAtIndex:indexPath.row] objectForKey:@"node_title"];
detailViewController.articleDetail = [Doctors objectAtIndex:indexPath.row];
[detailViewController.featureImage sd_setImageWithURL:[NSURL URLWithString:cellImageLink]];
[self.navigationController pushViewController:detailViewController animated:YES];
}
DetailViewController.h
{
IBOutlet UIScrollView *scroller;
IBOutlet UILabel *firstnameLabel;
IBOutlet UILabel *descriptionLabel;
IBOutlet UILabel *bodyLabel;
IBOutlet UIImageView *featureImage;
}
@property (nonatomic, copy) NSDictionary *articleDetail;
@property (strong, nonatomic) UIImageView *featureImage;
@property (strong, nonatomic) NSString *cellImageLink;
DetailViewController.m
- (void)viewDidLoad
{
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 5000)];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
firstnameLabel.text = [articleDetail objectForKey:@"node_title"];
descriptionLabel.text = [articleDetail objectForKey:@"Opening Paragraph"];
bodyLabel.text = [articleDetail objectForKey:@"Body"];
featureImage.image = [articleDetail sd_setImageWithURL:[NSURL URLWithString:cellImageLink]];
}
答案 0 :(得分:1)
如果你使用像SDWebImage这样的东西,那么你可以调用上面的相同代码:
[detailViewController.featureImage setImageWithURL:[NSURL URLWithString:secondLink]];
如果图像已下载,它会从缓存中提取图像,否则会将其下载。