2011-01-31 13 views
10

を示していない私は、次のコードを持っている:UIImageViewイメージ

@interface NeighborProfileViewController : UIViewController { 
    UIImageView * profPic; 
    UITextView * text; 
    UIButton * buzz; 
    NSString * uid; 
    NSMutableData *responseData; 
    NSDictionary * results; 
} 

@property (nonatomic, retain) IBOutlet UIImageView * profPic; 
@property (nonatomic, retain) IBOutlet UITextView * text; 
@property (nonatomic, retain) IBOutlet UIButton * buzz; 
@property (nonatomic, retain) NSString * uid; 

@end 

は、ここで私は私が私が正しくIB経由UIImageViewを有線考える.mファイル

@implementation NeighborProfileViewController 
@synthesize uid; 
@synthesize profPic; 
@synthesize buzz; 
@synthesize text; 


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    NSURL *url = //some URL to the picture; 
    NSData *data = [NSData dataWithContentsOfURL:url]; 
    UIImage *img = [[[UIImage alloc] initWithData:data] autorelease]; 
    self.profPic = [[UIImageView alloc] initWithImage: img]; 
} 

viewDidLoadに持っているものです。私はUIImageViewからファイル所有者のprofPicへのアウトレットを持っています。私は間違って何をしていますか?

答えて

13

デフォルトの画像を設定する場合は、self.profPic = [UIImageView]に電話した後、または画面から削除しても表示されますか? この問題は、self.profPicが古いイメージビューを解放して、作成したばかりのイメージビューに置き換えたときに発生すると思います。古いUIImageViewインスタンスは、IBで定義したすべてのプロパティとともに、おそらくスーパービューから自動的に削除されます。ダウンロードした画像が表示されないのはなぜですか。

あなたがUIImageViewを作成するためにIBを使用した場合、あなたは(すでに完全にインスタンスUIImageViewである)新しいImageViewのを作成したいとprofPicに割り当てないでください。 [profPic setImage:img];に電話して、profPicイメージビューの画像を変更してみてください。自動解放を使用すると、ここでの問題はないが

+0

私の頭を数時間叩いていました。イメージを設定する前にイメージビューを再度割り当てていました。ありがとう@thelaws – sErVerdevIL

2

@Equinoxは

[profPic setImage:img]; 

代わりの

self.profPic = [[UIImageView alloc] initWithImage: img]; 

を使用しています。 あなたも

self.profPic = [[UIImageView alloc] initWithImage: img]; 

でこれ

UIImage *img = [[UIImage alloc] initWithData:data] ; 
    [profPic setImage:img]; 
    [img release]; 

問題のような何かを行うことができますあなたが今profPicのための別のメモリロケーションを作成しているし、それはあなたのIBにUIImageViewにprofPicなくなりポイントを意味していることですもうこれ以上

関連する問題