将代码添加到故事板的UIImageview中

时间:2013-06-15 20:19:17

标签: objective-c xcode

我正在尝试从网址获取图片并将其显示在UIImageview中。 但是,我无法将我的代码连接到我的图像,因为我不知道如何。 以前我只是制作了一个nib文件并在那里进行编码,但是因为我将我的应用程序转移到iOS 6并想使用storyboard我不知道如何实现同样的事情:

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString * imageURL = [NSString stringWithFormat:@"http://app-content.app.com/api_ios/images/%@.png",
    [[NSUserDefaults standardUserDefaults] objectForKey:@"setup"]];
    NSURL* url = [NSURL URLWithString: imageURL];
    NSData * imageData = [NSData dataWithContentsOfURL:url];
    UIImage * image = [UIImage imageWithData:imageData];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
}

如您所见,我正在从网站加载图片,并使用NSUserdefaults中的字符串更改URL中的字符串。 我想将imageview与我storyboard中的图片相关联,但它不会让我,也不能在UIimageview上使用标识符。 使用storyboard进行此操作的正确方法是什么?

1 个答案:

答案 0 :(得分:-1)

佩德罗斯是对的,IBoutlet没有以正确的方式连接。 它现在正在运作。

相关问题