Search code examples
objective-ccocoacocoa-sheet

beginSheet modalForwindow: nil position?


I'm trying to understand how

- (void)beginSheet:(NSWindow *)sheet modalForWindow:(NSWindow *)docWindow modalDelegate:(id)modalDelegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo

chooses the position on my window since it's modal for no window ? (i passed nil to `modalForWindow:)

The first position is the one defined in the Interface builder. Once I closed it for the first time, each time a re-open it, it center in the half top of the screen. Isn't possible to always open it a the same position ?

thx


Solution

  • Use -[NSApplication runModalForWindow:] if you simply want to display a modal window.

    https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/nsapplication_Class/Reference/Reference.html#//apple_ref/occ/instm/NSApplication/runModalForWindow: