2010-09-21 112 views
0

我有一個小問題的方法,我已經實現了以下方法 打開圖像:在調用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]; 
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; 
[self.view addSubview:imgView]; 

}

但我怎麼能實現在viewDidLoad中這種方法()這個類的方法。 請問有人可以幫我嗎?

回答

1

如果這是在您的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中的。

+0

哦,是的,這是我搜查的方式! – Marco 2010-09-21 06:40:04

+0

太棒了!你可能想考慮接受答案,那麼:p – Toastor 2010-09-21 07:29:17