I am trying to implement a NSWindowController subclass with new xib-file, I read up in lots of books, and researched on StackOverflow, but none of the steps provided made my window show, nor did the subclass code get executed. The new xib-file has its File's Owner set to "LogNavigatorController" and connections to the window and its contents have been made.
My AppDelegate.h:
#import <Cocoa/Cocoa.h>
@class LogNavigatorWindowController;
@interface AppDelegate : NSObject <NSApplicationDelegate>
{
LogNavigatorWindowController *logsWindowController;
}
@end
My 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
My 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
My 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
You don't need to create the window property since it is already available for NSWindowController subclasses. Maybe that causes the problem.
Also your init method contains a lot of code that doesn't belong there. Remove
[self loadWindow];
[self showWindow:@"Log Navigator"];
[self.window makeKeyAndOrderFront:nil];
as well as replace
self = [super initWithWindowNibName:@"LogNavigatorWindowController"];
with
self = [super init];
You may want to remove the init method at all, since you don't need it in your case.
and move
[self myDirectoryLogFunction];
to the windowDidLoad method.
Also always check that the code for instantiating the window controller (in your case from the app delegates didFinishLaunching: ) is called. Sometimes it helps to create a new project and test there, if you may have changed too much within the original project and by accident removed delegate connections or similar.