I am using Cocoa with Obj C on Mac Tiger.
I have a textfield in a panel where path of xml file will be entered. Also I have a button "Browse" which will show the file open dialog for selection of file. When OK clicked, the file name is updated in the textfield. For this purpose I am having the following code in awakeFromNib:
In the browse button action, I am having following code:
The code for textDidChange is as follows:
My problem is that when I am editing I am able to see the message, but when browse button is clicked and selecting the file and setting the string using "setStringValue:", it's not calling the notification function. Why?
I have a textfield in a panel where path of xml file will be entered. Also I have a button "Browse" which will show the file open dialog for selection of file. When OK clicked, the file name is updated in the textfield. For this purpose I am having the following code in awakeFromNib:
Code:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:NSControlTextDidChangeNotification object:filePath];
//filePath is the outlet for text field
In the browse button action, I am having following code:
Code:
- (IBAction)onBrowse:(id)sender
{
int result;
NSArray* types = [NSArray arrayWithObject:@"xml"];
NSSavePanel *sPanel = [NSSavePanel savePanel];
[sPanel setAllowedFileTypes:types];
result = [sPanel runModalForDirectory:NSHomeDirectory() file:nil];
if (result == NSOKButton)
{
NSString* fName = [NSString stringWithString:[sPanel filename]];
[filePath setStringValue:fName];
}
}
The code for textDidChange is as follows:
Code:
- (void)textDidChange:(NSNotification *)aNotification
{
if([aNotification object] == filePath)
{
Log(@"User changing the text"); //Log is user defined method to write to a file.
}
}
My problem is that when I am editing I am able to see the message, but when browse button is clicked and selecting the file and setting the string using "setStringValue:", it's not calling the notification function. Why?