2011-01-22 1 views
0

음, 저는 Mac에서 프로그래밍하는 법을 배우고 있습니다. 답변을 검색하는 것에 지쳐 있습니다. 내 프로그램에서 내가 잘못한 것을 설명 할 수 있습니까?프로그램이 웹 이미지를로드하여 사용자 정의보기에 표시하는 방법은 무엇입니까?

먼저 내 창에 2 개의 버튼을 드래그했습니다 (이미지로드 및 언로드). 그런 다음 사용자 정의보기 항목을 드래그하여 Test_Loading_ImagesAppDelegate로 수행 한 작업을 여기에 표시합니다. 시간 : 그 후

#import <Cocoa/Cocoa.h> 

@interface Test_Loading_ImagesAppDelegate : NSView { 
    NSWindow *window; 
    IBOutlet NSView *mypicture; 
} 

- (IBAction)LoadImage: (id)sender; 
- (IBAction)Unload: (id)sender; 


@property (assign) IBOutlet NSWindow *window; 

@end 

, 나는 일반적으로 인터페이스 빌더에 물건을 연결하고 Test_Loading_ImagesAppDelegate했다. m : 사전에

#import "Test_Loading_ImagesAppDelegate.h" 

@implementation Test_Loading_ImagesAppDelegate 

@synthesize window; 

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 
    // Insert code here to initialize your application 
} 
-(IBAction)LoadImage: (id) sender { 
    NSURL *myurl; 
    NSImage *image; 
    NSData *myurldata; 
    myurl = [NSURL URLWithString:@"http://....jpg"]; 
    myurldata = [NSData dataWithContentsOfURL:myurl]; 
    image = [NSImage initWithData:myurldata]; 
    [mypicture setImage: image]; 

} 

-(IBAction)Unload: (id) sender { 

//Well, still thinking how I'm going to do this, and I would like to make another question: If I dealloc the View or something else the image will disappear? 

} 

@end 

감사합니다.

답변