【发布时间】:2012-03-08 23:37:57
【问题描述】:
我有一个带有图像名称列表的UITableViewController。单击名称时,图像的 URL 设置在 ImageViewController 中,然后 UITableViewController 与包含 UIImageView 的 ImageViewController (与插座相连)。在ImageViewController 的viewDidLoad 中,我将UIImageView 设置为来自URL 的图像,但是当我在模拟器上运行它时,只有一个黑屏出现在图像应该出现的位置。
对转场的一点视觉描述(其中 -> 表示转场):
-
ImageListTableViewController–> ImageViewController(有UIImageView)
ImageListTableViewController.m
// The delegate here is the ImageViewController
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Show Image"]) {
[self setDelegate:segue.destinationViewController];
}
}
// getting URL and calling the protocol method (in ImageViewController) which sets
// the image as an @property
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *imageDict = [self.imageArray objectAtIndex:indexPath.row];
NSURL *imageURL = [FlickrFetcher urlForPhoto:imageDict format:FlickrPhotoFormatLarge];
NSLog([imageURL description]);
[self.delegate imageListTableViewController:self withURL:imageURL];
}
ImageViewController.m
#import "ImageViewController.h"
@implementation ImageViewController
@synthesize image = _image;
@synthesize imageView = _imageView;
- (void)imageListTableViewController:(ImageListTableViewController *)sender
withURL:(NSURL *)imageURL;
{
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
self.image = [UIImage imageWithData:imageData];
}
#pragma mark - View lifecycle
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
// nothing
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
[self.imageView setImage:self.image];
}
- (void)viewDidUnload
{
[self setImageView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
@end
对正在发生的事情有任何想法吗? 谢谢!
【问题讨论】:
标签: ios uiimageview imageview uitableview