在 viewDidLoad() 中调用方法

发布于 2024-09-24 17:35:48 字数 430 浏览 1 评论 0原文

我有一个小问题,我已经实现了以下方法 我如何在此类

- (void)ladeImage {
id path = @"http://172.23.1.63:8080/RestfulJava/pics";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];  
UIImage *img = [[UIImage alloc] initWithData:data];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
[self.view addSubview:imgView];

但是

的 viewDidLoad() 方法中实现此方法。 有人可以帮我吗?

I have a little Problem, i have implemented the following method to
open an Image:

- (void)ladeImage {
id path = @"http://172.23.1.63:8080/RestfulJava/pics";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];  
UIImage *img = [[UIImage alloc] initWithData:data];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
[self.view addSubview:imgView];

}

But how i can implement this method in the viewDidLoad() Method of this class.
Could someone help me, please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃素的狼 2024-10-01 17:35:48

如果这是在您的 UIViewController 子类的实现中,那么只需复制并;将 ladeImage 方法中的代码粘贴到 viewDidLoad 中(xcode 将为您准备方法实现并注释掉它们,如果您启动 VC 子类,则需要取消注释它)。

它应该看起来像这样:

-(void)viewDidLoad {

   [super viewDidLoad];

   id path = @"http://172.23.1.63:8080/RestfulJava/pics";
   NSURL *url = [NSURL URLWithString:path];
   NSData *data = [NSData dataWithContentsOfURL:url];  
   UIImage *img = [[UIImage alloc] initWithData:data];
   UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
   [self.view addSubview:imgView];

}

当然,您可以保持原样,只在 viewDidLoad 的实现中调用 [self ladeImage];

If this is within your implementation of a UIViewController subclass, then just copy & paste the code from within your ladeImage method into viewDidLoad (xcode will prepare method implementations for you and comment them out if you start a VC subclass, you need to uncomment it).

It should look like this:

-(void)viewDidLoad {

   [super viewDidLoad];

   id path = @"http://172.23.1.63:8080/RestfulJava/pics";
   NSURL *url = [NSURL URLWithString:path];
   NSData *data = [NSData dataWithContentsOfURL:url];  
   UIImage *img = [[UIImage alloc] initWithData:data];
   UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
   [self.view addSubview:imgView];

}

of course you could leave things as they are and just call [self ladeImage]; in your implementation of viewDidLoad.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文