如何在Cocos2dx中修改加载CocoStudio的TextField内容
展开全部
两个代理方法 一个是点击return 缩回键盘
还有一个是对textField的输入进行监听
前提是需要对textField进行代理监听
//UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
{
//用户结束输入
[textField resignFirstResponder];
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange NSRange)range replacementString NSString*)string // return NO to not change text
{
//判断是否超过 ACCOUNT_MAX_CHARS 个字符,注意要判断当string.leng>0
//的情况才行,如果是删除的时候,string.length==0
int length = textField.text.length;
if (length >= ACCOUNT_MAX_CHARS && string.length >0)
{
return NO;
}
NSCharacterSet *cs;
cs = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];
NSString *filtered =
[[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
BOOL basic = [string isEqualToString:filtered];
return basic;
}
还有一个是对textField的输入进行监听
前提是需要对textField进行代理监听
//UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
{
//用户结束输入
[textField resignFirstResponder];
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange NSRange)range replacementString NSString*)string // return NO to not change text
{
//判断是否超过 ACCOUNT_MAX_CHARS 个字符,注意要判断当string.leng>0
//的情况才行,如果是删除的时候,string.length==0
int length = textField.text.length;
if (length >= ACCOUNT_MAX_CHARS && string.length >0)
{
return NO;
}
NSCharacterSet *cs;
cs = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];
NSString *filtered =
[[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
BOOL basic = [string isEqualToString:filtered];
return basic;
}
启帆信息
2024-11-19 广告
2024-11-19 广告
启帆信息是英伟达中国区代理商,原厂授权代理,提供全面的软件技术解决方案以及NVIDIA以太网产品、交换机等产品,欢迎前来咨询!...
点击进入详情页
本回答由启帆信息提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询