Iphone 在viewDidLoad()中调用方法
我有一个小问题,我已经实现了以下方法 打开图像:Iphone 在viewDidLoad()中调用方法,iphone,void,viewdidload,Iphone,Void,Viewdidload,我有一个小问题,我已经实现了以下方法 打开图像: - (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]; UIIm
- (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()方法中实现这个方法。
有人能帮我吗?如果这是在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];
}
当然,您可以让事情保持原样,只需调用
[self ladeImage]代码>在您的viewDidLoad实现中。哦,是的,这就是我搜索的方式!伟大的你可能想考虑接受答案,然后:P