如果要弹出一个自定义的window,可以创建一个新的window xib文件,并通过NSBundle来加载。xib的window属性有一个选项,就是visible at lauch,如果勾选的,执行下面代码时:

    [NSBundle loadNibNamed: @"RegisterWindow" owner: self];


    [NSApp beginSheet: sheet

  modalForWindow: window

modalDelegate: self

  didEndSelector:	@selector(didEndSheet:returnCode:contextInfo:)

  contextInfo: nil];

 

上面代码,自定义的窗口无法附在父窗口上;如果要让刚加载的窗口附在父窗口上,必须取消勾选visible at lauch选项。

  

//    NSRect rect = NSMakeRect(20, 20, 200, 200);
//    NSUInteger windowStyle = NSResizableWindowMask;
//    NSWindow *window = [[NSWindow alloc] initWithContentRect:rect styleMask:windowStyle backing:NSBackingStoreBuffered defer:NO];
//    
//    [NSApp beginSheet:edit.window
//       modalForWindow:[NSApp mainWindow]
//        modalDelegate:nil
//       didEndSelector:nil
//          contextInfo:nil];
//    [NSApp runModalForWindow: window];
//    
//    [NSApp endSheet:window];
//    [window orderOut:self];

  

posted on 2015-04-13 14:02  墓厄  阅读(847)  评论(0编辑  收藏  举报