- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRang

善洲 2014-04-29 07:40:23
怎么实现这个代理。
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string :(id)sender
{
NSCharacterSet *cs;
//textField.delegate = self;
if(textField == phone)
{
NSLog(@"phone 数字");
cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
BOOL basicTest = [string isEqualToString:filtered];
if(!basicTest)
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示"
message:@"请输入数字"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];

[alert show];
//[alert release];
return NO;
}

}
return YES;
//其他的类型不需要检测,直接写入
//return YES;
}

这个委托是放在.m文件实现还是再建立个类别,在xib文件中还需要设置什么吗?


简单来说就是实现这个判断委托。
...全文
2226 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ReyZhang 2014-05-05
  • 打赏
  • 举报
回复
添加当文本框输入改变时的通知 
[[NSNotificationCenter defaultCenter] addObserver:self 
        selector:@selector(textUpdated)
        name: UITextFieldTextDidChangeNotification
        object:self.inputValueField];
kinghome 2014-05-04
  • 打赏
  • 举报
回复
.m 或 .h 加入协议 <UITextFieldDelegate> UITextField.delegate = self;
lyc_omg 2014-04-30
  • 打赏
  • 举报
回复
放在.m文件中就可以了
ArcRain 2014-04-30
  • 打赏
  • 举报
回复
给你的UITextField设置个delegate就行了,放在同一个.m里也可以的。

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧