我想用新的xib文件實現NSWindowController子類,我讀了很多書,並在StackOverflow上進行了研究,但沒有提供任何步驟使我的窗口顯示,也沒有執行子類代碼。新的xib文件將其文件所有者設置爲「LogNavigatorController」,並已連接到窗口及其內容。如何使用xib文件正確實現NSWindowController子類
我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
Thanks @trojanfoe刪除了屬性及其實現代碼(綜合),仍然沒有骰子。 –