怎样获得TableView中TextField.text
2个回答
展开全部
两个代理方法 一个衫空是点击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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
UITextField *textField=[[UITextField alloc] initWithFrame:CGRectMake(250, 50, 150, 22)];
textField.tag=[indexPath row];
textField.delegate=self;
textField.placeholder = @"请改册输入";
textField.font = [UIFont fontWithName:@"Times New Roman"镇升 size:25];
[textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[cell addSubview:textField];
//第二步,实现回调函数
- (void) textFieldDidChange:(id) sender {
NSNumber *tag=[NSNumber numberWithInt:[sender tag]];
UITextField *_field = (UITextField *)sender;
NSLog(@"御歼老tag%@",tag);
NSLog(@"_field%@",[_field text]);
}
textField.tag=[indexPath row];
textField.delegate=self;
textField.placeholder = @"请改册输入";
textField.font = [UIFont fontWithName:@"Times New Roman"镇升 size:25];
[textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[cell addSubview:textField];
//第二步,实现回调函数
- (void) textFieldDidChange:(id) sender {
NSNumber *tag=[NSNumber numberWithInt:[sender tag]];
UITextField *_field = (UITextField *)sender;
NSLog(@"御歼老tag%@",tag);
NSLog(@"_field%@",[_field text]);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询