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

之后,我在 Interface Builder 上正常链接了一些东西,并制作了 Test_Loading_ImagesAppDelegate。

#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

提前致谢。

4

1 回答 1

0

好吧,再次来到这里后,我发现了这个http://www.markj.net/iphone-asynchronous-table-image/ 它适用于 iPhone,但可以轻松适应 OS X。谢谢。

于 2011-08-20T13:58:05.670 回答