UITextView delegate inconsistency...

Member
Posts: 35
Joined: 2009.01
Post: #1
Hello,

I've figured this out, read for fun only!


I am implementing high score functionality and having some strange trouble with my UITextView. The delegate receives the beginEditing notification but nothing else. Initially, beginEditing was not invoked, but then I moved my call to -setDelegate: to after when it was added as a subview, as adding a subview apparently modifies a control's delegate...

Code below:

Code:
@implementation GameStateHighScores

-(id) initWithScore:(GLfloat)_score {
    
    self = [super init];
    
    if (self) {
        
        theScore = _score;
        
        playerNameField = [[[UITextField alloc] initWithFrame:PlayerNameFieldFrame] autorelease];
        [playerNameField setBackgroundColor:[UIColor whiteColor]];
        [playerNameField setFont:[UIFont systemFontOfSize:24.0f]];
        [playerNameField setTextAlignment:UITextAlignmentCenter];
        [playerNameField setKeyboardAppearance:UIKeyboardAppearanceAlert];
        
        [[GameView sharedView] addSubview:playerNameField];
        [playerNameField setDelegate:self];
        
        [playerNameField becomeFirstResponder];
    }
    
    return self;
}

+(id) highScoresStateWithScore:(GLfloat)_score {
    
    return [[[self alloc] initWithScore:_score] autorelease];
}

-(void) textFieldDidBeginEditing:(UITextField *)textField {
    
    NSLog(@"mmm.");
}

-(BOOL) textFieldShouldEndEditing:(UITextField *)textField {
    
    return YES;
}

-(void) textFieldDidEndEditing:(UITextField *)textField {
    
    NSLog([textField text]);
}

@end

When viewing the console, "mmm" is displayed as expected. But nothing occurs when I hit return. Perhaps hitting return doesn't automatically send a didEndEditing notification?

I'd appreciate any advice, and I'll keep you posted if I come across the solution.

Thanks,

- Dave H.
Quote this message in a reply
Member
Posts: 35
Joined: 2009.01
Post: #2
the method I was looking for was

-(BOOL) textFieldShouldReturn:(UITextField *)textField

Blah

Blush
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  What should I use, subclassing or delegate (opengl es)? riruilo 2 2,414 Dec 18, 2008 08:43 PM
Last Post: AnotherJake