English 中文(简体)
无法隐藏键盘 。
原标题:Can t hide the keyboard with shouldChangeCharactersInRange

这是我的代码:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 
{
    NSCharacterSet *nonNumberSet = [[NSCharacterSet characterSetWithCharactersInString:@"אבגדהוזחטיכלמנסעפצקרשתףץםן"] invertedSet];

    // max charcters
    NSUInteger newLength = [textField.text length] + [string length] - range.length;
    if (newLength > 14)
        return NO;

    // allow backspace
    if (range.length > 0 && [string length] == 0) {
        return YES;
    }
    // do not allow . at the beggining
    if (range.location == 0 && [string isEqualToString:@"."]) {
        return NO;
    }
    if ((range.location > 0) && (([[textField.text substringWithRange:NSMakeRange((range.location -1), 1)] isEqualToString:@"ף"]) || ([[textField.text substringWithRange:NSMakeRange((range.location -1), 1)] isEqualToString:@"ץ"]) || ([[textField.text substringWithRange:NSMakeRange((range.location -1), 1)] isEqualToString:@"ם"]) || ([[textField.text substringWithRange:NSMakeRange((range.location -1), 1)] isEqualToString:@"ן"])))   
    {
        return NO;
    }

    // set the text field value manually
    NSString *newValue = [[textField text] stringByReplacingCharactersInRange:range withString:string];
    newValue = [[newValue componentsSeparatedByCharactersInSet:nonNumberSet] componentsJoinedByString:@""];
    textField.text = newValue;
    // return NO because we re manually setting the value
    return NO;
}

我只是想当您点击 < kbd> return 键盘会消失时做。 我无法这样做。 在哪里添加以及如何添加它?

最佳回答

如果您想要在点击 return 键后隐藏键盘, 在您的代码中添加以下内容:

if ([string isEqualToString:@"
"]) {
    [theTextField resignFirstResponder];
    return NO;
}

希望有帮助

问题回答

在UIText Field 文本的代表方法中,字段“应返回”的使用:-

[yourTextField resignFirestResponder];

同时在你们班级上执行UIText的外地远程发射,

yourTextField.delegate=self;

创建 IB Action 并连接到您的文本字段视图中。

-(IBAction)doneEditing:(id)sender
{
     [sender resignFirstResponder];
}

选择事件 < em> 在连接文件所有者时退出 < / em> 结束 。





相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签