来自应用程序的新 NSWindow - 不可能完成的任务?

2024-02-21

好吧,我做错了什么?
1.创建了cocoa app和appDelegate,命名为:window2AppDelegate
2. 窗口AppDelegate.h

#import "PrefWindowController.h"
@interface window2AppDelegate : NSObject <NSApplicationDelegate> {
    NSWindow *window;
    PrefWindowController * ctrl;
}

@property (assign) IBOutlet NSWindow *window;
- (IBAction) buttonClick:(id)sender;
- (IBAction) buttonCloseClick:(id)sender;
@end


3.在xib编辑器中,连接到窗口控制器的窗口-设置为appdelegate,将buttonclick操作设置为按钮
4、创建

#import <Cocoa/Cocoa.h>
@interface PrefWindowController : NSWindowController {
@private

}
@end

#import "PrefWindowController.h"
@implementation PrefWindowController

- (id)init {
    self = [super initWithWindowNibName: @"PrefWindow"];
    return self;
}

- (void)dealloc {
    // Clean-up code here.
    [super dealloc];
}

- (void)windowDidLoad {
    [super windowDidLoad];
    // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}

@end


5.创建了名为 PrefWindow 的新 xib 文件,窗口 IBOutlet 从其控制器连接到窗口(也将控制器设置为 PrefWindowController)选项“启动时可见”未选中!我想在单击按钮时看到这个窗口。
6. 实现window2AppDelegate

#import "window2AppDelegate.h"
@implementation window2AppDelegate
@synthesize window;

- (id) init {
    if ((self = [super init])) {
        ctrl = [[PrefWindowController alloc] init];
    if ([ctrl window] == nil)
        NSLog(@"Seems the window is nil!\n");
    }
    return self;
}

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
    return YES;
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
}

- (IBAction) buttonClick:(id)sender {
//    [[ctrl window] makeKeyAndOrderFront:self]; this doesn't work too :(
NSLog(@"it is here");
[ctrl showWindow:sender];
}

- (IBAction) buttonCloseClick:(id)sender {
    [window close];
}

@end


7. 在我构建并运行应用程序后:closebutton 关闭应用程序,但单击按钮 - 不会向我显示 PrefWindow!?为什么以及我做错了什么?不要告诉我在 cocoa Objective-C 中显示其他窗口比在“愚蠢的”Java 或 C# 中更困难吗?


终于我解决了这个问题!在 PrefWindow 的笔尖编辑器中,我必须执行以下操作:将文件的所有者类设置为:NSWindowController then 将文件所有者的窗口 IBOutlet 连接到我的(首选项)窗口。经过 6 天的尝试失败后,Google 成功了。
无论如何,感谢您的所有回复和时间!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

来自应用程序的新 NSWindow - 不可能完成的任务? 的相关文章

  • 原生插入符位置 macos cocoa

    我希望能够使用 cocoa 或 appleScript 获取 Mac High Sierra 中任何应用程序内的全局插入符位置 我已经使用 NSEvent 来获取键盘和鼠标挂钩 但是有没有办法获取插入符位置挂钩 插入符号与鼠标位置不同 它会
  • 将 CFIndex 转换为 NSUInteger?

    我如何转换typedef signed long CFIndex to typedef unsigned int NSUInteger 如果我使用一个可以吗 CFIndex作为类型的参数NSUInteger 我还没有铸造它 编译者似乎也不介
  • 从 iPhone 设备查找当前国家/地区

    我必须在 iPhone 设置中获取当前国家 地区 谁能告诉我如何在 iPhone 应用程序中获取当前国家 地区 我必须使用当前国家 地区来解析需要传递当前国家 地区的 RSS 提要 请帮我找到那个国家 提前致谢 要查找用户选择的语言所在的国
  • 检测用户何时清除通知中心的通知

    我的应用程序需要知道用户是否使用清除按钮从通知中心删除 清除应用程序通知 是否可以检测用户何时从通知中心删除通知或抓取通知中心上的一组通知 你 即App 无法与NotificationCenter交互 NotificationCenter与
  • 如何使用自动布局在自定义 UITableViewCell 内动态设置 UITextView 高度

    I have UITableView every tableViewCell is custom Inside my customTableViewCell is a UITextView TextViews frame is pin or
  • 如何从 Xcode 4 中的实体创建用户界面?

    我已经用核心数据进行了几天的实验 并且在过去的几个小时里尝试找出如何从 xcode 4 中的实体创建 UI 根据我一直在阅读的书籍 您必须选择将核心数据实体拖到界面生成器中的窗口中 但是当我在 xcode 4 中执行此操作时 没有任何反应
  • 如何从 Xib 文件加载自定义 UITableViewCell?

    问题很简单 如何加载自定义UITableViewCell来自 Xib 文件 这样做可以让您使用 Interface Builder 来设计您的单元 由于内存管理问题 答案显然并不简单 这个线程 https stackoverflow com
  • 如何读取 Xcode 6.1 Instruments .trace 文件?

    我一直在尝试阅读 trace文件 我使用生成的custom仪器模板 仪器 自动机 分配 Leaks using 仪器 https developer apple com library mac documentation Developer
  • 返回一个dispatch_async获取的变量[重复]

    这个问题在这里已经有答案了 基本上 一个方法需要返回一个在dispatch async中获取的NSDictionary 这是我尝试过的 NSDictionary fetchNSDictionary dispatch queue t Queu
  • 如何从 UILabel 创建图像?

    我目前正在 iPhone 上开发一个简单的类似 Photoshop 的应用程序 当我想要展平图层时 标签位于良好的位置 但字体大小不佳 这是我要展平的代码 UIGraphicsBeginImageContext CGSizeMake wid
  • Objective-C 使用字符串池吗?

    我知道Java https stackoverflow com questions 3801343 what is string pool in java and C http msdn microsoft com en us librar
  • Cocoa 基于文档的应用程序中的 MVC

    我目前正在对我的应用程序进行重构和重组 我意识到模型和视图及其控制器之间的一些分离已经减少 我希望进行一些清理 我的应用程序中使用了几个关键类 NSPersistentDocument NSWindowController 和模型类 NSP
  • 如何检测 UISearchBar/UITextField 输入中的暂停?

    我有以下 UISearchbar 代码 void searchBar UISearchBar searchBar textDidChange NSString searchText UIApplication sharedApplicati
  • NSArray 对象的 RACSignal

    我的 ViewController 上有一个 NSArray 的 ViewModel 对象 property 非原子 强 NSArray viewModels ViewModel 对象看起来像这样 interface ViewModel N
  • 使用 UIKeyCommand 检测删除键

    任何人都知道如何使用检测 删除 键UIKeyCommand在 iOS 7 上 当人们在使用 Swift 时遇到问题时 我认为用 Objective C 和 Swift 编写一个小型的 完整的例子可能是一个很好的答案 请注意 Swift 没有
  • 如何修复 ReactiveCocoa(带有 CocoaPods)的安装?

    这里是新手 尝试将 ReactiveCocoa 2 2 4 和 CocoaPods 安装到项目中 但在运行时遇到错误 我用过github 上的这个 podspec https github com CocoaPods Specs blob
  • NSDateFormatter:根据 currentLocale 的日期,不包含年份

    这不会太难吧 我想显示不带年份的日期 例如 8 月 2 日 美国 或 02 08 德国 它也必须适用于许多其他语言环境 到目前为止 我唯一的想法是对年份进行正常格式 然后从生成的字符串中删除年份部分 我认为你需要看一下 NSString d
  • ios 11 - UIBarButtonItem 内的 UIButton 导致自动布局错误

    我在将 UIButton 添加到 UIBarButtonItem 时遇到了一个已知问题 我尝试按照建议添加自动布局约束堆栈溢出 https stackoverflow com a 46336639 505603但我收到如下所述的错误 UIB
  • UITextView:内存使用量巨大

    我在 UITextView 中遇到了内存使用过多的问题 我正在将 50Kb ascii 文本文件加载到 NSString 中 并将其分配给应用程序中空 UITextView 组件的 text 属性 这立即使我的内存占用量增加了 100Mb
  • Objective C (iphone) 关于发布的问题

    如果我创建一个视图 并将其添加为子视图并将其添加到数组中 是否必须释放它两次 UIView cat UIView alloc initWithFrame someFrame self view addSubview cat self ani

随机推荐