I don’t know why this is happening, but I’ll often populate a variable if I 
know it from another class and can’t find it from another.  By that, I mean if 
you know the window in the class that opens the preferences, get it and set it 
in the MasterViewController.   

> On Sep 4, 2021, at 12:26 PM, Gabriel Zachmann via Cocoa-dev 
> <cocoa-dev@lists.apple.com> wrote:
> 
> I access the window of a view by two different ways, in the controller and in 
> the view, resp., and in the controller, I always get a nil pointer.
> 
> 
> In my app, I have a subclass of NSView, MyView, declared like this:
> 
> @interface MyView : NSView <NSTextViewDelegate, CALayerDelegate, 
> CAAnimationDelegate>
> {
>    NSWindow * window_;
>    ...
> }
> @property (readwrite) NSWindow * window_;
> 
> 
> In one of MyView's instance methods, I save the window like this:
> 
> - (void) viewWillMoveToWindow: (NSWindow *) newWindow
> {
>    window_ = newWindow;
>    ...
> 
> 
> Also in MyView, I have this line to interrogate the styleMask at some point 
> later during runtime:
> 
>    if ( [window_ styleMask] & NSWindowStyleMaskFullScreen )
>        ...
> 
> This works fine, window_ has a proper value (as a pointer), and styleMask 
> returns values as expected.
> 
> 
> However, I have pretty much the same line in my MasterViewController, which 
> does not work.
> 
> 
> In the MasterViewController, I create an instance of MyView like this:
> 
> - (void) viewDidLoad
> {
>    [super viewDidLoad];
>    myview_ = [[MyView alloc] initWithFrame: self.view.frame isPreview: NO ];
>    [self.view addSubview: myview_]; 
>    ...
> 
> 
> Then, in MasterViewController's showPreferences:, I have this code:
> 
> - (IBAction) showPreferences: (id) sender
> {
>    if ( [myview_.window_ styleMask] & NSWindowStyleMaskFullScreen )
>       ...
> 
> 
> Here, myview_.window_  is always 0.
> 
> 
> How could that be?
> 
> Puzzled, Gabriel.
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> 
> This email sent to z...@mac.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to