Please help me ! how to fix the position of NSWindow ?

Hello everybody,


I have a NSwindowController < NSWindowDelegate > (with windowWillUseStandardFrame implemented) which is supposed to fix the position of my window.


Except never this method is called ! Nevertheless there is indeed a delegate...


In fact in the launch of my soft, the system makes little as it wants: it cascades me windows or keeps me the last position of every window.


I tried to deactivate the cascading, the same problem...


All the directives concerning the NSWindow seem to be ignored !


I do not know if it is a pure coincidence, but since I passed of a macBook 13p under 10.6 (XCode 4.0.1) in a mini mac with screen 24p under 10.7 (XCode 4.3), everything seems not to work any more as before ?!


I wish I can align in the topleft of my screen all my windows (I tried all the concerned methods, the same problem) to loosen me of the resolution of the screen.


If you have an idea, it will be welcome.


Thanks you in advance.


FM.

Mac mini, Mac OS X (10.7.4), XCode 4.3

Posted on Jun 7, 2012 9:44 AM

Reply
10 replies

Jun 7, 2012 11:18 AM in response to OUNAS

The windowWillUseStandardFrame:defaultFrame: delegate method is not used to position the window, it is used with NSWindow's zoom: method in determining what the window frame can be zoomed to. The initial position of the windows can be set in the Interface Editor, but you will need to post some code and/or a better description about what you are wanting to do.

Jun 7, 2012 11:43 AM in response to red_menace

Thanks you for your answer.


i would like to fix the position of my NSWindow for example in X coordinate = 10 and y coordinate = 10 (top left in screen) at runtime.


can i use awakeFromNib method to do this ?


if yes, how ?


- (void) awakeFromNib {

[[selfwindow] setAutorecalculatesContentBorderThickness:YESforEdge:NSMinYEdge];

[[selfwindow] setContentBorderThickness:30forEdge:NSMinYEdge];

}



thanks.

Jun 8, 2012 10:35 AM in response to red_menace

Thanks you for this information.


I tried certain count of methodes told in this document. None work !


I think i don't understand the principle of window positionning.



1/ Concretely, to what level we do have to fix the position of a NSWindow ?


In the "awakeFromNib" method of the NSWindowController?


or in a customized NSWindow class ?


2/ in Interface Builder : what are the considerations to take into account for window positionning ?



I find very openly the management of the positioning of a window very complex while it is a basic task !


Thanks.


FM

Jun 8, 2012 4:34 PM in response to OUNAS

I still can't tell what you are doing. If your window is defined in a nib, then you can use NSWindowController's initWithWindowNibName method, and the position of the initial window would be whatever has been set in the nib (the initial position can be set in the Interface Editor's Size Inspector). The setShouldCascadeWindows method (default is yes) determines if the window should cascade in relation to other document windows. If you are manually positioning your windows, you can use NSWindow's cascadeTopLeftFromPoint method with the initial top left coordinates, and use the returned NSPoint in the next call to cascade that window, and so on.

Jun 8, 2012 9:28 PM in response to OUNAS

OUNAS wrote:



I find very openly the management of the positioning of a window very complex while it is a basic task !


Thanks.


FM

Bonjour Ounas,


It is not complex, within Cocoa simple things are easy to implement (and complex are possible). If you find it the other way you made a mistake somewhere.

In your case I would start by putting a breakpoint in the methods and run the application in Debugg Mode.

And if :

- your method is not called

- your window is 0x0 inside the method

Closely look in Interface Builder if the connection is correct between your window and its variable in code and if your controller object is well assigned as its delegate. For that just select the window object in the nib and do a right/control click on it to see if it is well connected with controller's objects (alternatively use the Menu -> View -> Utilities -> Show Connections Inspector).


As for the time to call your "fix" method what about the "- (void)windowDidLoad" call in your window controller subclass ?

I had lots of troubles to get it called when I started with Cocoa. For it to works you have to be sure the window is well connected in IB to your window variable. And you need to load that f*¿!^ fichue window by any call to it via your controller like


//After call window is 0x0 in the debugger if you look at it by unfolding the triangles self>controller>NSWindowController

controller = [[RTWindowControlleralloc]init];

//This one will trigger the controller's windowDidLoad method

[controllershowWindow:self];

//a simple [controller window] is enough to bring it to life



hth


laurent

Jun 10, 2012 10:11 AM in response to laurent demaret

Thanks you for this information.


But nothing works ! i am sorry ! 😢


My window always jumps of the screen.


I read that it could have problems of "jumping" for windows.


to resume :

** i've a NSWindow in NIB (with delegate to NSWindowController) - the connections are correct between NIB and Controller


list of properties checked :

close, minimize, title bar, textured, shadow, release when closed, hide on deactivate, restorable


** in my NSWindowController, i've awakeFromNib method.


I would just want to move this window at top left on my screen.


I tried all concerned methods, but nothing works correctly !


maybe that my use of these methods is not correct...


I am perplexed... 😕


FM

Jun 10, 2012 10:32 AM in response to OUNAS

Hi,

As I told you before put a breakpoint in your awakeFromNib method and watch the value of your window variable inside this method.

Could be nil because you did not bring it to life at that time. If nil all your work will fail silently because messages sent to nil do fail silently..

You have to call it for it to exists. Maybe it's not off screen but just nil at that moment.

Jun 10, 2012 11:00 AM in response to OUNAS

You won't need to do anything in your controller's awakeFromNib unless you are setting up other stuff, but your window should show up at the initial location set in the Interface Editor (note that the coordinates it uses are the bottom left corner) when your application starts up, for example:


AppDelegate.h

@class MyWindowController; @interface AppDelegate : NSObject {     MyWindowController *theWindowController;     MyWindowController *anotherWindowController; } // whatever else @end


AppDelegate.m

- (void)applicationDidFinishLaunching:(NSNotification*)notification {      theWindowController = [[MyWindowController alloc] initWithWindowNibName:@"YourWindow"];      if (theWindowController != NULL)           [theWindowController showWindow:self];                 anotherWindowController = [[MyWindowController alloc] initWithWindowNibName:@"YourWindow"];      if (anotherWindowController != NULL)           [anotherWindowController showWindow:self]; // etcetera }


The other windows should automatically cascade, since that is the default, otherwise you can manually cascade them with the previously mentioned methods.

Jun 12, 2012 8:11 AM in response to red_menace

I've found the solution of my problem.


In my context, it was enough to use "setFrameOrigin" 😀 instead of "SetFrameTopLeftPoint" !


now, it's possible to fix correctly the position of my windows.


It explains that I understood why it did not work - my code being similar to your code, it was very strange !


Thanks you for your help.


FM

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Please help me ! how to fix the position of NSWindow ?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.