我有一個UIImageView
,我無法獲取圖像並設置爲顯示。無法爲UIImageView設置圖像
viewDidLoad
albumContainer = [[UIImageView alloc]initWithFrame:CGRectMake(112, 7, 97, 97)];
[self.view addSubview:albumContainer];
方法
來自不同類
NSLog(@"URL:%@",url);
//URL is defined by different class
//URL is http://www.....882546328.jpg (I abbreviated it, but it is a valid url)
NSData *imageData = [NSData dataWithContentsOfURL:url];
NSLog(@"URL LENGTH:%d",[imageData length]);
// URL LENGTH:90158
UIImage *tempImage = [UIImage imageWithData:imageData];
[albumContainer setImage:tempImage];
全碼被稱爲
PlayerViewController
-(void)viewDidLoad{
[super viewDidLoad];
playerView = [[AlbumViewController alloc]initWithNibName:@"AlbumViewController" bundle:nil];
}
-(void)playMusic{
playerView.url = [NSURL URLWithString:imagePathForm];
playerView.songData = receivedData;
[loadingSong stopAnimating];
[playerView play];
}
AlbumViewCont輥
- (void)viewDidLoad
{
[super viewDidLoad];
albumContainer = [[UIImageView alloc]initWithFrame:CGRectMake(112, 7, 97, 97)];
[self.view addSubview:albumContainer];
url = [NSURL URLWithString:@""];
}
-(void)play{
NSLog(@"SONGDATA:%d",[songData length]);
player = [[AVAudioPlayer alloc] initWithData:songData error: nil];
[player stop];
player.delegate = self;
player.numberOfLoops = 0;
player.volume = 0.5;
[player prepareToPlay];
[player play];
NSLog(@"URL:%@",url);
NSData *imageData = [NSData dataWithContentsOfURL:url];
NSLog(@"URL LENGTH:%d",[imageData length]);
UIImage *tempImage = [UIImage imageWithData:imageData];
[albumContainer setImage:tempImage];
}
我檢查和albumContainer記錄爲NULL
你能解釋一下「從不同班級調用的方法」是什麼意思?如果你使用'albumContainer',這意味着這個方法在同一個類中被調用,這是真的嗎? – 2012-02-02 21:52:02
我發佈的代碼來自類albumViewController。從不同的類playerViewController我正在使用[專輯setImage],這是上面張貼的方法。 – Matt 2012-02-02 22:02:27
第二個代碼片段中的albumContainer怎麼樣?它是如何定義的?嘗試評論你的代碼或編輯它來添加上癮信息。謝謝。 – 2012-02-02 22:12:45