• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Notification
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Re: NSRectFill not supporting compositing?????
  • Next by Date: RE: SQLite as an embeddable framework
  • Previous by thread: Re: I hate NSMatrix...
  • Next by thread: Re: Stripping headers from embedded frameworks
  • Index(es):
    • Date
    • Thread