曾经被UITextField给坑一把
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];