Notification
Notification
- Subject: Notification
- From: Stephane Curzi <email@hidden>
- Date: Tue, 20 May 2003 11:01:16 -0400
Hi
I'm building a simple text editor and I made an information panel that
reads the number of characters...
My problem is that it works for the first window but as soon as I make
a new window, the info dont update anymore. It still works for the
first window.
What am I doing wrong ?
#import "TXTInfoController.h"
@implementation TXTInfoController
-(void)awakeFromNib
{
NSTextView *text = [[NSApp mainWindow] firstResponder];
NSString *textStorage = [text string];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(textDidChange:)
name:NSTextDidChangeNotification
object:text];
[textLengthField setIntValue:[[text textStorage] length]];
[wordLengthField setIntValue:[[textStorage
componentsSeparatedByString:@" "] count]];
[paragraphLengthField setIntValue:[[textStorage
componentsSeparatedByString:@"\n\n"] count]];
}
-(void)textDidChange:(NSNotification *)notification
{
NSTextView *text = [[NSApp mainWindow] firstResponder];
NSString *textStorage = [text string];
[textLengthField setIntValue:[[text textStorage] length]];
[wordLengthField setIntValue:[[textStorage
componentsSeparatedByString:@" "] count]];
[paragraphLengthField setIntValue:[[textStorage
componentsSeparatedByString:@"\n\n"] count]];
}
- (IBAction)updateInfo:(id)sender
{
NSTextView *text = [[NSApp mainWindow] firstResponder];
NSString * textStorage = [text string];
[textLengthField setIntValue:[[text textStorage] length]];
[wordLengthField setIntValue:[[textStorage
componentsSeparatedByString:@" "] count]];
[paragraphLengthField setIntValue:[[textStorage
componentsSeparatedByString:@"\n\n"] count]];
}
@end
Another question, I'm not sure about the way I'm reading the textView
form the main window, is there a better way ??
Thanks
--
Stiphane Curzi
email@hidden
http://www.projetsurbain.com/
_______________________________________________
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.