【发布时间】:2014-01-30 09:28:27
【问题描述】:
我正在尝试使用新的 xib 文件实现 NSWindowController 子类,我阅读了很多书籍,并对 StackOverflow 进行了研究,但是提供的步骤都没有显示我的窗口,也没有执行子类代码。新的 xib 文件的 File's Owner 设置为“LogNavigatorController”,并且已建立到窗口及其内容的连接。
我的 AppDelegate.h:
#import <Cocoa/Cocoa.h>
@class LogNavigatorWindowController;
@interface AppDelegate : NSObject <NSApplicationDelegate>
{
LogNavigatorWindowController *logsWindowController;
}
@end
我的 AppDelegate.m:
#import "AppDelegate.h"
#import "LogNavigatorWindowController.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
logsWindowController = [[LogNavigatorWindowController alloc] initWithWindowNibName:@"LogNavigatorWindowController"];
[logsWindowController showWindow:self];
}
@end
我的 LogNavigatorWindowController.h:
#import <Cocoa/Cocoa.h>
@interface LogNavigatorWindowController : NSWindowController
{
NSArray *directoryList1;
NSArray *directoryList2;
NSMutableArray *directoryList;
NSMutableArray *filePaths1;
NSMutableArray *filePaths2;
}
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSTableView *logsTableView;
@property (unsafe_unretained) IBOutlet NSTextView *logsTextView;
@property (assign) IBOutlet NSArrayController *LogListController;
@property (retain) NSMutableArray *logsArray;
- (void) myDirectoryLogFunction;
@end
我的 LogNavigatorController.m:
#import "LogNavigatorWindowController.h"
@interface LogNavigatorWindowController ()
@end
@implementation LogNavigatorWindowController
@synthesize logsTableView;
@synthesize logsTextView;
@synthesize window;
- (id)init
{
self = [super initWithWindowNibName:@"LogNavigatorWindowController"];
[self loadWindow];
[self showWindow:@"Log Navigator"];
[self.window makeKeyAndOrderFront:nil];
if (self)
{
// Initialization code here.
[self myDirectoryLogFunction];
}
return self;
}
- (void)windowDidLoad
{
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
- (void) myDirectoryLogFunction
{
NSLog(@"Code execution test successful");
}
@end
【问题讨论】:
-
NSWindowController已经有一个window“属性”,所以我怀疑你自己提供是问题所在。 -
感谢@trojanfoe 删除了属性及其实现代码(合成),仍然没有骰子。
标签: objective-c xcode xib nswindowcontroller