Hi WT,
have you tried - to avoid everything discussed in thread - to use
implementation like below one? For what you want it could be more
proper avoiding discussed issues and at the same time it hides
everything into your subclass (wrapped delegate class details are
hidden into module):

#import <Foundation/Foundation.h>

@class CustomTextFieldDelegate;

@interface CustomTextField : UITextField

{

    @private

    CustomTextFieldDelegate * _customDelegate;

}

@end

#import "CustomTextField.h"

@interface CustomTextFieldDelegate:NSObject<UITextFieldDelegate>

@end

@implementation CustomTextFieldDelegate

-(BOOL)textField:(UITextField*)text_field
shouldChangeCharactersInRange: (NSRange) range replacementString:
(NSString*) string

{

    NSLog(@"-textField: shouldChangeCharactersInRange: replacementString:");

    return YES;

}

-(BOOL)textFieldShouldBeginEditing:(UITextField*)text_field

{

    NSLog(@"-textFieldShouldBeginEditing:");

    return YES;

}

- (void)textFieldDidBeginEditing:(UITextField*)text_field

{

    NSLog(@"-textFieldDidBeginEditing:");

}

- (BOOL) textFieldShouldEndEditing: (UITextField*) text_field

{

    NSLog(@"-textFieldShouldEndEditing:");

    return YES;

}

- (void) textFieldDidEndEditing: (UITextField*) text_field

{

    NSLog(@"-textFieldDidEndEditing:");

}

- (BOOL) textFieldShouldClear: (UITextField*) text_field

{

    NSLog(@"-textFieldShouldClear:");

    return YES;

}

- (BOOL) textFieldShouldReturn: (UITextField*) text_field

{

    NSLog(@"-textFieldShouldReturn:");

    [text_field resignFirstResponder];

    return YES;

}



@end

@implementation CustomTextField

-(void)awakeFromNib

{

    _customDelegate = [[CustomTextFieldDelegate alloc] init];

    self.delegate = _customDelegate;

    self.text = @"Hello World";

    [super awakeFromNib];

}

-(void)dealloc

{

    [_customDelegate release]; _customDelegate = nil;

    [super dealloc];

}

@end

On Sat, Jul 25, 2009 at 9:06 PM, WT <jrca...@gmail.com> wrote:
>
> Hello all,
>
> I need to create a subclass of UITextField for a text field that performs 
> some control over its own editing. The obvious idea is to make the subclass 
> instance set itself up as its own delegate, but that freezes the app as soon 
> as the delegate method -textFieldDidBeginEditing returns.
>
> Looking at Activity Monitor, the CPU usage of the app goes up to nearly 100%. 
> I've since created the most trivial app with a UITextField subclass that 
> conforms to the UITextFieldDelegate protocol and which sets itself up as its 
> own delegate and, sure enough, the app freezes.
>
> Here's the subclass. Set up a project then add a text field to a view and 
> make its class be CustomTextField. Compile and run, and watch it freeze when 
> you attempt to edit the text in the field.
>
> So... why can't the field be its own delegate?
>
> Thanks in advance.
> Wagner
>
>
> // CustomTextField.h:
>
> #import <UIKit/UIKit.h>
>
> @interface CustomTextField: UITextField <UITextFieldDelegate>
> {
> }
>
> @end
>
> // CustomTextField.m:
>
> #import "CustomTextField.h"
>
> @implementation CustomTextField
>
> - (void) awakeFromNib
> {
>    super.delegate = self;
>    super.text = @"Hello world";
>
>    NSLog(@"awakeFromNib called - delegate set to self");
> }
>
> // ========================================================================= 
> //
>
> - (BOOL) textField: (UITextField*) text_field
>         shouldChangeCharactersInRange: (NSRange) range
>         replacementString: (NSString*) string
> {
>    NSLog(@"-textField: shouldChangeCharactersInRange: replacementString:");
>    return YES;
> }
>
> // ========================================================================= 
> //
>
> - (BOOL) textFieldShouldBeginEditing: (UITextField*) text_field
> {
>    NSLog(@"-textFieldShouldBeginEditing:");
>    return YES;
> }
>
> // ========================================================================= 
> //
>
> - (void) textFieldDidBeginEditing: (UITextField*) text_field
> {
>    NSLog(@"-textFieldDidBeginEditing:");
> }
>
> // ========================================================================= 
> //
>
> - (BOOL) textFieldShouldEndEditing: (UITextField*) text_field
> {
>    NSLog(@"-textFieldShouldEndEditing:");
>    return YES;
> }
>
> // ========================================================================= 
> //
>
> - (void) textFieldDidEndEditing: (UITextField*) text_field
> {
>    NSLog(@"-textFieldDidEndEditing:");
> }
>
> // ========================================================================= 
> //
>
> - (BOOL) textFieldShouldClear: (UITextField*) text_field
> {
>    NSLog(@"-textFieldShouldClear:");
>    return YES;
> }
>
> // ========================================================================= 
> //
>
> - (BOOL) textFieldShouldReturn: (UITextField*) text_field
> {
>    NSLog(@"-textFieldShouldReturn:");
>    [self resignFirstResponder];
>    return YES;
> }
>
> // ========================================================================= 
> //
>
> @end
>
> _______________________________________________
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/peter.blazejewicz%40gmail.com
>
> This email sent to peter.blazejew...@gmail.com
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to