objective-c - 打开我自己的 Mac 应用程序首选项

标签 objective-c macos cocoa osx-mountain-lion

我是 Cocoa 应用程序的新手。
我想以编程方式打开应用程序的首选项窗口

通过谷歌搜索, 我刚刚找到了 --> [[NSWorkspace共享工作空间] openFile:@"MyApp.prefPane"];"

如有任何帮助,我们将不胜感激。---

谢谢。

最佳答案

您可以像应用程序中的任何其他窗口一样打开首选项窗口:

在应用程序委托(delegate)类中:

- (IBAction)showPreferencePanel:(id)sender {
    if (!_preferenceController)
        _preferenceController = [[PreferenceController alloc] init];

    [_preferenceController showWindow:self];
}

其中PreferenceController是:

@interface PreferenceController : NSWindowController <NSWindowDelegate, NSToolbarDelegate, FontChooserViewDelegate>
...
@end

MainMenu.xib 中,showPreferencePanel 方法像这样 Hook :

enter image description here

关于objective-c - 打开我自己的 Mac 应用程序首选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19217739/

相关文章:

cocoa - 为什么我的自动释放对象没有被释放?

cocoa - 在 cocoa 中以编程方式打开和关闭窗口

objective-c - NSFileHandleDataAvailableNotification 文件重复无新数据(导致 CPU 使用率非常高)

objective-c - 使用performSelectorOnMainThread时如何定位父对象?

swift - 如果调用 NSApp.terminate,DispatchQueue 线程会被清理吗?

ios - OpenGL 4.1 中顶点数组对象未正确绑定(bind)

iphone - quartz 2D : draw from a CGContext to another CGContext

iphone - 用图像覆盖 MKMapView

ios - 翻转 UICollectionViewCell 会导致其他单元格翻转

ios - 删除 uicollectionview 顶部的额外空间