discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: please explain me that:


From: Nicolas SANCHEZ
Subject: Re: please explain me that:
Date: Thu, 05 Feb 2004 09:09:23 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4

reuss wrote:
I would like to limit the number of characters to input in my textfield

I posed my question about it, and I got responses, but it is too concise
for me. Could someone help me by examples to understand the following:


When using an NSTextView, you would implement
-textView:shouldChangeTextInRange:replacementString: in the delegate and
rejecting the change (by returning NO) if it would cause the string to
become too long. In an NSTextField, the text field instance sets itself
as the delegate for the NSTextView field editor, so you could write a
custom subclass of NSTextField that implemented
-textView:shouldChangeTextInRange:replacementString: and use that
instead of a plain NSTextField.

(An alternative would be to use formatters, but that isn't implemented
yet.)

- Alexander Malmberg


thanks
andras

that's ok, i've the solution, get the files in attachement, it's a subclass of NSTextField.
#ifndef _MYTEXTFIELD_H_
#define _MYTEXTFIELD_H_

#include <AppKit/AppKit.h>

@interface myTextField: NSTextField

- (id)initWithFrame: (NSRect)aFrame;
- (BOOL)textView:(NSTextView *)aTextView 
shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString 
*)replacementString;

@end

#endif
#include "myTextField.h"

@implementation myTextField

- (id)initWithFrame: (NSRect)aFrame
{
  [super initWithFrame: aFrame];

  [self setDelegate: self];

  return self;
}

- (BOOL)textView:(NSTextView *)aTextView 
shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString 
*)replacementString
{
  if ([[self stringValue] length] > 10)
    return NO;
  else
    return YES;
}

@end

reply via email to

[Prev in Thread] Current Thread [Next in Thread]