UIImageView没有显示图像

ahe*_*ang 10 iphone objective-c

我有以下代码:

@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
Run Code Online (Sandbox Code Playgroud)

下面是我在viewDidLoad.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];
}
Run Code Online (Sandbox Code Playgroud)

我想我正确地连接了UIImageView通道IB.我有一个从UIImageView文件所有者的profPic 出口.我究竟做错了什么?

the*_*aws 13

如果您要设置默认图像是在通话后保持可见self.profPic = [UIImageView]还是从屏幕上删除?我认为在self.profPic发布旧图像视图以将其替换为您刚刚创建的图像视图时会出现此问题.旧UIImageView实例以及您在IB中定义的所有属性可能会自动从超级视图中删除.这就是为什么你没有看到下载的图像.

如果你曾经IB创建过UIImageView那么你不想创建一个新的ImageView并将其分配给profPic(已经完全实例化UIImageView).尝试调用[profPic setImage:img];哪个只会更改profPicimageview 中的图像.