Imageview根本没有加载

时间:2014-07-15 20:17:26

标签: ios objective-c

在viewcontroller.h中,我正在这样做。

@property( nonatomic, strong)IBOutlet UIImageView*showLogo;

在viewcontroller.m中我这样做。

   NSString*path=@"http://www.stboston.com/wp-content/uploads/2012/08/iStock_000004791880_1.jpg";

    NSURL *url = [NSURL URLWithString:path];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *img = [[UIImage alloc] initWithData:data ];

 _showLogo=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 500)];
     _showLogo.image=img;

1 个答案:

答案 0 :(得分:1)

尝试将其直接加载到_showLogo.image

_showLogo=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 500)];
_showLogo.image = [UIImage imageWithContentsOfURL:@"http://www.stboston.com/wp-content/uploads/2012/08/iStock_000004791880_1.jpg"];
[self.view addSubview:_showLogo];

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.stboston.com/wp-content/uploads/2012/08/iStock_000004791880_1.jpg"]];
_showLogo.image = [UIImage imageWithData:imageData];
[self.view addSubview:_showLogo];