views:

29

answers:

1

Hello Users,

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?

+1  A: 

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.

Toastor
oh yes, this is the way i have searched!
Marco
Great! You might want to consider accepting the answer, then :p
Toastor