I have modified your code try like this below:-
- (void) closeBox
{
// called when the Ok button pressed
//Commented this line
// [NSApp abortModal];
[mwin performClose:mwin];// Modified this line
}
//Modified below notification just comment the parameter
- (void)closeClicked/*:(NSNotification *)notification*/
{
[NSApp abortModal];
}
- (void) openBox
{
NSRect frame = NSMakeRect(0, 0, 300, 250);
mwin = [[[[NSWindow alloc] initWithContentRect:frame
styleMask:NSClosableWindowMask |NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO]retain]autorelease];
//Modified notification below
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(closeClicked)
name:NSWindowWillCloseNotification
object:nil];
NSButton * bn;
bn = [[[NSButton alloc] initWithFrame:NSMakeRect(10, 10, 100, 20) ] autorelease];
[bn setButtonType:NSMomentaryPushInButton];
[bn setTitle:@"Ok"];
[bn setTarget:self];
[bn setAction:@selector(closeBox)];
[[mwin contentView] addSubview:bn];
[NSApp runModalForWindow:mwin];
}