Unable to set NSWindow position

I have a class that extends NSWindowController, and I'm trying to position its window. The window displays all expected content and functions correctly, but when I try to position the starting location on the screen in the initWithWindowNibName method, the position does not change. Here is the code:

NSPoint p = NSMakePoint(100, 50);
[[self window] setFrameTopLeftPoint:p];

This seems very straightforward, and I'm not sure what the problem is.

Thanks for any ideas.

(found a problem. I did not have a window connected to the class in IB.)

+3
source share
2 answers

Weahah has the right idea, although I will try to expand it a little.

If you try to add this line to your method initWithWindowNibName::

NSLog(@"window == %@", [self window]);

, :

window == (null)

, nil, init* , IBOutlet "".

nil : . , , [nil doSomething];

, IBOutlet . Wevah, , , -

- (void)awakeFromNib;

NSWindowController, :

- (void)windowDidLoad;

, ...

+3

awakeFromNib.

+1

Source: https://habr.com/ru/post/1767271/


All Articles