2010-06-04 62 views
0

我使用的标记字段设置为文本标志字段自动跳跃文本视野下一个字段:如何重置输入字段的键盘?

- (BOOL)findNextEntryFieldAsResponder:(UIControl *)field { 
    BOOL retVal = NO; 
    for (UIView* aView in mEntryFields) { 
    if (aView.tag == (field.tag + 1)) { 
     [aView becomeFirstResponder]; 
     retVal = YES; 
     break; 
    } 
} 
return retVal; 
} 

它工作正常在自动跳转到下一个字段的条件时Next键被按下。但是,我的情况是,键盘是不同的一些领域。例如,一个字段是数字&标点符号,下一个是默认(字母键)。对于数字&标点键盘确定,但下一个字段将保持相同的布局。它要求用户按123键返回ABC键盘。

我不确定是否有任何方法来重置字段的键盘作为其在xib中定义的键盘?不确定是否有任何API可用?我想我必须做的是以下代表?

-(void)textFieldDidBegingEditing:(UITextField*) textField { 
    // reset to the keyboard to request specific keyboard view? 
    .... 
} 

好的。我发现a solution close to my case by slatvik

-(void) textFieldDidBeginEditing:(UITextField*) textField { 
    textField.keyboardType = UIKeybardTypeAlphabet; 
} 

然而,在以前的文本字段的情况下是数字,键盘保持数字时自动跃升到下一个字段。有没有办法将键盘设置为字母模式?

回答

0

最后我找到了解决问题的方法。就我而言,我喜欢使用Entry或Next键来自动跳转到下一个可用字段。如果按顺序排列的两个字段的键盘完全不同,则键盘更改应该没问题。但是,如果键盘是数字模式,而下一个是字母模式,那么自动跳转不会导致相同的键盘改变模式。

主要原因是我调用findNextEntryFieldAsResponder:方法是在textFieldShouldReturn:delegate方法中完成的。该调用导致下一个字段将成为应答:

... 
[aView becomeFirstResponder]; // cause the next fields textFieldDidBeginEditing: event 
... 

我发现这个在我的NSLog调试消息:

textFieldShouldReturn: start 
    findNextEntryFieldAsResponder 
    textFieldDidBeginEditing: start 
    ... 
    textFieldDidBeginEditing: end 
    ... 
textFieldShouldReturn: end 

我需要做的就是下一个字段作为响应了textFieldShouldReturn的:事件呼叫。我试图使用iphone的本地通知框架在textFieldShouldReturn中触发一个异步通知事件:并且它符合我的期望。

这里是我的更新代码:

- (BOOL)findNextEntryFieldAsResponder:(UIControl *)field { 
    BOOL retVal = NO; 
    for (UIView* aView in mEntryFields) { 
    if (aView.tag == (field.tag + 1)) { 
     if ([self.specialInputs containsObject:[NSNumber numberWithInt:aView.tag]]) { 
     NSNotification* notification = [NSNotification notificationWithName: 
      @"myNotification" object:aView]; 
     [[NSNotificationQueue defaultQueue] 
      enqueueNotification:notification postingStyle:NSPostWhenIdle 
      coaslesceMask:NSNotificationCoalescingOnName forModes:nil]; 
     [[NSNotifiationCenter defaultCenter] addObserver:self 
      selector:@selector(keyboardShowNofication:) 
      name:@"myNotification" object:nil]; 
     } 
     else { 
     [aView becomeFirstResponder]; 
     } 
     retVal = YES; 
     break; 
    } 
    } 
    return retVal; 
} 
... 
// Notification event arrives! 
-(void) keyboardShowNofication:(NSNotification*) notification { 
    UIResponder* responder = [notification object]; 
    if (responder) { 
    [responder becomeFirstResponder]; // now the next field is responder 
    } 
} 
... 
-(void) dealloc { 
    ... 
    // remember to remove all the notifications from the center! 
    [[NSNotificationCenter defaultCenter] removeObserver:self]; 
    ... 
} 

其中specialInputs为int值的NSArray的。这是一个属性可以设置一个列表标签作为特殊输入。实际上,我认为所有的输入都可以视为specialInputs,它也可以工作(只是更多的通知)。

我有a complete description of codes in my blog