我正在以编程方式创建一些UITextField
s,当我尝试委派它们时,我收到以下警告:
NAVPlanViewController *const __strong' 到不兼容类型的参数
id<UITextFieldDelegate>
textHeight = [[UITextField alloc] initWithFrame:CGRectMake(0, 120, 160, 40)];
[textHeight setDelegate:self];
在.c
我的课堂上,我添加了@interface NAVPlanViewController : UIViewController <UITextViewDelegate>
. 另外,我需要限制文本字段只接受数字,我想用这段代码来做,但因为我UITextField
无法Delegate
检查它:
- (BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string {
if (!string.length) {
return YES;
}
if ([string rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet]
invertedSet]].location != NSNotFound){
//do something;
return NO;
}