RE: What method to override to initialize fields on a form?
RE: What method to override to initialize fields on a form?
- Subject: RE: What method to override to initialize fields on a form?
- From: "Cristian Savu" <email@hidden>
- Date: Thu, 22 Aug 2002 09:06:30 +0300
>
-----Original Message-----
>
From: email@hidden
>
[mailto:email@hidden]On Behalf Of Jiva DeVoe
>
Sent: Thursday, August 22, 2002 8:31 AM
>
To: Cocoa-Dev
>
Subject: What method to override to initialize fields on a form?
>
>
>
AwakeFromNib only gets called when the nib is loaded, not
>
every time the
>
window is shown. I want to initialize a text box every time
>
a window is
>
shown. What method should I override?
In theory, your problem is not so complicated because the COCOA provides us
NSWindowDidExposeNotification.
In practice, they forgot to connect the notification so it's useless.
What you should do is to subclass NSWindow and send by yourself the missing
notification.
This is the code I use for this purpose. I'm sending also a
RSWindowWillExposeNotification and this will be the message you need (to
init the fields before exposure). Probably the code can be improved but, for
me, it's all I need.
Best regards,
Cristian
//SAMPLE CODE
#import <Cocoa/Cocoa.h>
//class RSWindow : - subclass of NSWindow
// - used to add NSWindowDidExposeNotification and
RSWindowWillExposeNotification notification messages.
//The first one is missing from apple's implementation (they forgot
about it!!!!) and the second one is mine, used to initialize the content
of the window just before it is displayed
@interface RSWindow : NSWindow
{
}
- (void)orderFront:(id)sender;
- (void)makeKeyAndOrderFront:(id)sender;
@end
//
// RSWindow.m
// R2003
//
// Created by Cristian Savu on Tue Jul 23 2002.
// Copyright (c) 2001 __MyCompanyName__. All rights reserved.
//
#import "RSWindow.h"
#import "RSApplicationController.h"
#import "RSApplicationDefs.h"
@implementation RSWindow
- (void)orderFront:(id)sender
{
//send notification : NSWindowWillExposeNotification
[[NSNotificationCenter defaultCenter]
postNotificationName:RSWindowWillExposeNotification
object:self
userInfo:nil];
[super orderFront:sender];
//send notification : NSWindowDidExposeNotification
[[NSNotificationCenter defaultCenter]
postNotificationName:NSWindowDidExposeNotification
object:self
userInfo:nil];
}
- (void)makeKeyAndOrderFront:(id)sender
{
//send notification : NSWindowWillExposeNotification
[[NSNotificationCenter defaultCenter]
postNotificationName:RSWindowWillExposeNotification
object:self
userInfo:nil];
[super makeKeyAndOrderFront:sender];
//send notification : NSWindowDidExposeNotification
[[NSNotificationCenter defaultCenter]
postNotificationName:NSWindowDidExposeNotification
object:self
userInfo:nil];
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.