美文网首页
曾经被UITextField给坑一把

曾经被UITextField给坑一把

作者: 风雪夜归人_1fb0 | 来源:发表于2018-06-28 11:26 被阅读0次

 UITextField *tfText = [[UITextField alloc] initWithFrame:CGRectMake(30, 150, self.view.frame.size.width-60, 40)];

    tfText.delegate = self;

    tfText.borderStyle = UITextBorderStyleRoundedRect;

   // tfText.keyboardType =  UIKeyboardTypeNumberPad;

    tfText.placeholder = @"请输入标题";

    //用这个好点,系统的很坑爹,第一位数删不掉

    [tfText addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];

    [self.view addSubview:tfText];

#pragma makr UITextFieldDelegate

- (void)textFieldDidEndEditing:(UITextField *)textField{

    NSLog(@"textField=%@",textField.text);

}

//不然键盘不退回去

- (BOOL)textFieldShouldReturn:(UITextField *)textField;

{

    [textField resignFirstResponder];//回收键盘

    return YES;

}

- (void)textFieldDidChange:(UITextField *)textField{

    NSLog(@"textField=%@",textField.text);

}

 ==============================================================================

用系统的方法,曾经在这里被坑过,到最前面一位数字的时候,死活删不掉,就这方法,坑人

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

用这个来搞,干干净净,彻彻底底解决

[tfText addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];

相关文章

网友评论

      本文标题:曾经被UITextField给坑一把

      本文链接:https://www.haomeiwen.com/subject/xnhgyftx.html