好吧,我正在学习如何在 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
提前致谢。