さて、私は Mac でプログラミングする方法を学んでいて、答えを探すのにうんざりしています。私のプログラムで何が間違っていたのか説明してもらえますか?
まず、ウィンドウで 2 つのボタン (イメージの読み込みとアンロード) をドラッグしました。次に、カスタム ビュー アイテムをドラッグし、Test_Loading_ImagesAppDelegate で行ったことを次に示します。h :
#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
前もって感謝します。