我有一个UITableViewController
与图像名称列表。单击名称时,图像的URL将在ImageViewController
中设置,然后UITableViewController
继续变为ImageViewController
,其中包含UIImageView
(与插座连接)。在ImageViewController
的viewDidLoad
中,我将UIImageView
设置为来自URL的图像,但是当我在模拟器上运行它时,图像应该只出现黑屏。UIImageView不显示从UITableViewController设置图像
的SEGUE的一个小的视觉描述(其中 - >装置赛格瑞):
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
对发生了什么事有什么想法? 谢谢!
非常感谢ElJay,当我回家时我会试试这个。为了将来的参考,什么时候使用代表是适当的时间?我正在关注斯坦福大学的系列讲座,以及我能够告诉他们以这种方式使用的讲座。 – gg67 2012-03-09 02:58:37
代表是一种很好的方法,可以告诉班级您已完成某项工作。它们可以用来让调用类知道某些事情已经完成,并且可以传回对象(例如,当您记录用户并需要传回UserInfo时)。他们没有真正使用(从我的经验)来呼吁某事。斯坦福的视频很棒。 – 2012-03-09 03:08:39
谢谢。好吧,试过后,我仍然只是黑屏。此外,延续到图像需要更长的时间。思考? – gg67 2012-03-09 03:21:13