0

Okay so 'return' is 'insertNewline', I love that, but where in god's green earth is the insertSpace?

So i'm trying to invoke a spellcheck (for a keyword) after the user completes the word (aka, when they hit space bar or return ). But daddy needs to detect space-bar. Heres the textView delegate method i'm implementing...

/* listen to commands */ 
-(BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector
{
    BOOL result = NO;
    if (@selector(insertNewline:) == aSelector) {
    // does something 
    result = YES; 
    return result; 
}
return result; 
4

1 回答 1

0

如下使用UITextView的委托方法来实现这个...

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
 replacementText:(NSString *)text
{
    // Any new character added is passed in as the "text" parameter
    if ([text isEqualToString:@"\n"]) {
        //code when return key pressed.
    }
    else if([text isEqualToString:@" "])
    {
        //code when space key pressed.
    }
    // For any other character return TRUE so that the text gets added to the view
    return TRUE;
}
于 2013-04-18T11:26:31.640 回答