3

何かをテストするために、OSX10.8でObjective-Cを使用してシングルウィンドウアプリケーションを作成しようとしました。私が作成したNSTextFieldがキーボード入力に応答しないことを除いて、すべてが正常に機能します。コードは次のとおりです。

#import <Cocoa/Cocoa.h>

@interface customizedView:NSView
    +(customizedView *)aCustomizedView;  // changed method name to follow convention
@end
@implementation customizedView
    +(customizedView *)aCustomizedView{
        customizedView *newView = [[[customizedView alloc] initWithFrame:NSMakeRect(0,0,400,300)] autorelease];
        NSTextField *tf = [[[NSTextField alloc] initWithFrame:NSMakeRect(200,150,150,50)] autorelease];
        [newView addSubview: tf positioned:NSWindowBelow relativeTo:newView];
        return newView;
    }

    -(void)windowWillClose:(NSNotification *)aNot{
        [NSApp terminate:self];
    }
@end

void setup(){
    NSWindow *aWindow = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,300) styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask backing:2 defer:NO] autorelease];
    customizedView *aView = [customizedView aCustomizedView];
    [aWindow setContentView:aView];
    [aWindow setDelegate:aView];
    [aView setNeedsDisplay:YES];
    [aWindow makeKeyAndOrderFront:nil];
}

int main(int argc, char **argv){
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSApplication *NSApp = [NSApplication sharedApplication];
    setup();
    [NSApp run]; [NSApp release]; [pool release];
    exit(EXIT_SUCCESS);
}

を使用してコンパイル

gcc -w filename.m -o tmp -framework Cocoa

カスタマイズしたNSViewのテキストフィールドに入力するためにキーボードを使用して入力できないことを除いて、すべてが機能します。マウスを使って貼り付けても大丈夫です。これまでのところ、なぜこれが起こるのか、私にはまだ理想がありません。このヒントを心から読んでくれたすべての人に前もって感謝します。

4

0 に答える 0