Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSTextField不';不响应键盘输入_Objective C_Nsview_Nstextfield - Fatal编程技术网

Objective c NSTextField不';不响应键盘输入

Objective c NSTextField不';不响应键盘输入,objective-c,nsview,nstextfield,Objective C,Nsview,Nstextfield,我试图在OSX10.8中使用Objective-C编写一个单窗口应用程序来测试一些东西。除了我创建的NSTextField不响应键盘输入之外,一切都正常。代码如下: #import <Cocoa/Cocoa.h> @interface customizedView:NSView +(customizedView *)aCustomizedView; // changed method name to follow convention @end @implementati

我试图在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);
}
除了无法使用键盘输入自定义NSView中的文本字段外,其他一切都正常工作。用鼠标粘贴是可以的。到目前为止,我仍然不知道为什么会发生这种情况,我提前向所有真诚阅读此技巧的人表示感谢

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