我有一個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