Reputation: 351
What I'm trying to do is create a method to an object which opens a window. In this window I want to output some properties of the object's instance. To do this I created a "Profile" subclass of NSObject, which has an NSWindowController property called "view".
@interface Profile : NSObject {
\\...
}
@property (readwrite, assign) NSWindowController *view;
Since I cannot connect "view" to the window with Interface Builder (or at least I don't know how) I have to do so with the "initWithWindowNibName". So I tried overriding the "Profile"'s init method like this:
-(Profile *)init{
self = [super init];
if(self){
[[self view] initWithWindowNibName:@"Profile"];
}
return self;
}
I don't know whether my approach is correct, fact is when I try showing the window it doesn't appear. Here's how I tried:
Profile *profile = [[Profile alloc] init];
[[profile view] showWindow:self];
Hope you can help :)
Upvotes: 1
Views: 807
Reputation: 9185
Don't you want something like:
@interface Profile:NSObject
@property (nonatomic, strong) NSWindowController *windowController;
@end
and:
- (Profile *)init {
self = [super init];
if( !self ) { return nil; }
self.windowController = [[NSWindowController alloc] initWithWindowNibName:@"Profile"];
return self;
}
and:
// show window
Profile *profile = [[Profile alloc] init];
[[profile windowController] showWindow:self];
(I'm assuming ARC.)
EDIT:
For clarity to the OP, I followed the his property nomenclature, which was to name the NSWindowController
property view
. It is confusing, though because a NSWindowController
is not a view. For clarity to others, I've changed it.
Upvotes: 2