标签: nswindowcontroller

打开新的NSWindowController

我是可可编程的新手。

我有一个主开关NSWindowController,想打开第二个子开关NSWindowController。似乎还是找不到代码。

有人可以帮忙吗?

cocoa nswindowcontroller

5
推荐指数
1
解决办法
2611
查看次数

NSWindow设置的帧高于屏幕

我需要帮助.我有一个像Adium这样的应用程序,带有垂直滑块.但我的应用程序会根据内容更改窗口高度.如果屏幕高度低于我app'a窗口高度,我的窗口会自动降低高度.

当我尝试将setFrame用于我的窗口并将window.frame.size.height设置为高于屏幕高度时,没有任何反应.

所以问题是:如何设置窗框高于屏幕高度?

cocoa objective-c nswindow nswindowcontroller

5
推荐指数
1
解决办法
871
查看次数

Mac OS X Cocoa单窗口应用程序架构

我无法理解如何以单一窗口应用程序在Mac OS X中工作的最佳方式设计应用程序.我更喜欢单个文档 - 单窗口应用程序(我不编写实用程序应用程序),但目前尚不清楚我应该初始化一个窗口内容.

在iOS上,我应该使用根视图控制器-[UIViewController viewDidLoad]-[UIViewController viewWillAppear:]方法来实现此目的.

你可以请教我任何教程或解释如何处理NSDocument - NSDocumentController - NSWindowController - NSViewController类?

谢谢你的回答.:-)

macos cocoa objective-c nsviewcontroller nswindowcontroller

5
推荐指数
1
解决办法
2614
查看次数

窗口关闭时释放NSWindowController

我正在构建一个Cocoa应用程序,并对使用窗口控制器有疑问.我们的想法是,如果用户从菜单栏中选择New,则会创建一个MyWindowController实例,它是NSWindowController的子类,并显示MyWindow.xib的新窗口.

我正在处理应用程序委托中的操作.从我在搜索周围的东西后看到的东西可以做到.一旦显示窗口,我没有任何理由再存储指向窗口控制器的指针,因为我分配了它,所以在显示窗口之前我也会自动释放它.

[[[[MyWindowController alloc] init] autorelease] showWindow:self];
Run Code Online (Sandbox Code Playgroud)

由于窗口很快就会释放,窗口会在屏幕上短暂显示然后消失.我找到了一个解决方案,我在-showWindow:方法中保留了窗口控制器,并在获得windowWillClose通知后让它自行释放.

- (IBAction)showWindow:(id)sender
{
    [self retain];
    [[NSNotificationCenter defaultCenter] addObserverForName:NSWindowWillCloseNotification
                                                      object:self.window
                                                       queue:nil
                                                  usingBlock:^(NSNotification *note) {
                                                      [self release];
                                                  }];
    [super showWindow:sender];
}
Run Code Online (Sandbox Code Playgroud)

有一个更好的方法吗?我搜索过Apple文档,但没有找到任何可以使用的实践.这听起来像它应该涵盖的非常基本的东西,所以也许我只是用错误的术语搜索.

cocoa memory-management objective-c nswindow nswindowcontroller

5
推荐指数
1
解决办法
2848
查看次数

如何使用红色窗口按钮检测我的窗口是否正在关闭?

我有一个对话窗口,可以通过自定义取消按钮或使用系统红色窗口按钮取消.取消对话框时,我需要执行一些简单的逻辑.如何检测到用户按下了红色按钮?

我知道我可以使用-windowWillClose:委托回调检测正在关闭的窗口.但是,当对话成功后以编程方式关闭窗口时,也会调用此回调.我也知道我可以简单地设置一个BOOL标志,但有更好的解决方案吗?如果我能检测到红色按钮激活,那将是最好的.

cocoa nswindow nswindowcontroller

5
推荐指数
1
解决办法
2146
查看次数

如何使用NSWindowController在标准应用程序中显示一个窗口?

我使用Xcode模板创建了一个新的空白标准应用程序.删除了MainMenu.xib中的窗口,我用xib创建了一个新的自定义NSWindowController子类.

它们被命名为"WYSunFlowerWindowController.h"和"WYSunFlowerWindowController.m".

然后我添加init函数,如下所示:

- (id)init
{
    NSLog(@"init()");

    return [super initWithWindowNibName:@"WYSunFlowerWindowController" owner:self];
}
Run Code Online (Sandbox Code Playgroud)

我的WYAppDelegate.m文件如下所示:

static WYSunFlowerMainWindowController* windowController = nil;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    if (windowController == nil) {
        windowController = [[WYSunFlowerMainWindowController alloc] init];
    }
    [[windowController window] makeKeyAndOrderFront:windowController];
}
Run Code Online (Sandbox Code Playgroud)

我有问题,在我启动应用程序后,窗口无法自我显示.谁能告诉我为什么?我的代码有什么问题吗?

我是Objective-C和可可的新手.所以我想我可能犯了一个愚蠢的错误,我自己无法弄明白.

更新:

这是我的项目来源.请看看,帮我弄清楚我的错误是什么.

https://dl.dropbox.com/u/3193707/SunFlower.zip

xcode cocoa objective-c nib nswindowcontroller

5
推荐指数
1
解决办法
1万
查看次数

NSWindow beginSheet completionHandler未调用

我在主窗口中显示一张纸.我使用以下代码展示工作表:

AddContactWindowController *addContact = [[AddContactWindowController alloc] initWithWindowNibName:@"AddContactWindow"];
addContact.currentViewController = myView;
self.addWindowController = addContact;

[self.view.window beginSheet: addContact.window completionHandler:^(NSModalResponse returnCode) {
    NSLog(@"completionHandler called");
}];
Run Code Online (Sandbox Code Playgroud)

AddContactWindowController是NSWindowController的子类.它内部有一个视图控制器.在视图内部是一个"关闭"按钮,它调用:

[[[self view] window] close];
Run Code Online (Sandbox Code Playgroud)

这会关闭窗口,但不会调用beginSheet中的completionHandler.这引起了我的问题.

有没有什么特别的方法我们应该关闭NSWindow表以便成功调用完成处理程序?我也尝试过,[[[self view] window] orderOut:self]但这也不起作用.

谢谢.

macos cocoa nsview nswindow nswindowcontroller

5
推荐指数
1
解决办法
5324
查看次数

斯威夫特的NSWindowController.使用Nib进行子类化和初始化

在测试Swift项目中,我是子类NSWindowController.我的NSWindowController子类旨在使用特定的Nib文件.因此,希望在初始化我的窗口控制器时,窗口控制器实例自动加载nib文件.在Objective-C中,这是通过以下方式实现的:

@implementation MyWindowController

- (id)init {
    self = [super initWithWindowNibName:"MyWindowNib"]
    if (self) {
        // whatever
    }
    return self
}

@end
Run Code Online (Sandbox Code Playgroud)

现在,在Swift中这是不可能的:init()不能调用super.init(windowNibName:),因为后者被声明不是指定的初始化器,而是作为方便的一个NSWindowController.

怎么能在Swift中完成?我没有看到一种直截了当的方式.

PS:我已经看到了关于这个主题的其他问题,但是,只要我能够理解,解决方案都指向通过调用初始化Window Controller init(windowNibName:).请注意,这不是理想的beheaviour.应该使用窗口控制器进行初始化init(),并且应该是窗口控制器本身"拾取"其Nib文件并加载它.

cocoa subclass nib nswindowcontroller swift

5
推荐指数
2
解决办法
884
查看次数

使用NSWindowController时出错

我很久以后就开始了一个新的Cocoa项目......我不知道为什么,但是当我通过NSWindowController调用xib时总是会出错.我所做的非常简单:我有一个新项目作为起点,然后我不想从Appdelegate调用xib,而是从NSWindowController的子类调用.然后输出告诉我:

2014-11-12 09:58:18.519 SimpleTest [8554:378690] ApplePersistence = NO

2014-11-12 09:58:18.671 SimpleTest [8554:378690]无法连接(窗口)出口(NSApplication)到(NSWindow):缺少setter或实例变量

好的,它在代码中看起来如何?我的Appdelegate看起来像这样:

#import "AppDelegate.h"
#import "MainWindowController.h"

@interface AppDelegate ()

@property (weak) IBOutlet NSWindow *window;
@property (strong) MainWindowController *mainWindowController;

@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    _mainWindowController = [[MainWindowController alloc] initWithWindowNibName:@"MainMenu"];
    [self.mainWindowController showWindow:self];
}

@end
Run Code Online (Sandbox Code Playgroud)

到目前为止没什么特别的.该MainWindowController如下所示:

#import "MainWindowController.h"

@interface MainWindowController ()
@property (weak) IBOutlet NSWindow *window;

@end

@implementation MainWindowController

- (id)initWithWindow:(NSWindow *)window
{
    self = [super initWithWindow:window];

    if (self != nil)
    {
        //do something
    }

    return self;
} …
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c nswindowcontroller

5
推荐指数
1
解决办法
3137
查看次数

自定义 NSWindowController 中的级联

我有一个基于文档的应用程序。我重写NSDocument'smakeWindowControllers以实例化自定义窗口控制器。它的初始化程序调用init(window: NSWindow?)其超类,即它不使用任何涉及 nib 文件的初始化程序。

如何进行级联工作(请参阅shouldCascadeWindows)?目前,每个窗口都在第一个屏幕上的相同位置打开。

我可以通过调用某些东西来重用现有的级联逻辑吗NSWindowController

如果我必须自己手动实现,我应该如何最好地获取最顶层文档窗口的位置?文档的潜在多个窗口中的哪一个应该是计算偏移量的窗口?

nsdocument appkit nswindowcontroller

4
推荐指数
1
解决办法
587
查看次数