怎样获得TableView中TextField.text
1个回答
展开全部
第1种//第一步,对组件增加监听器
[textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];//第二步,实现回调函数
- (void) textFieldDidChange:(id) sender {
UITextField *_field = (UITextField *)sender;
NSLog(@"%@",[_field text]);
}
第2种textField.delegate=self;...
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *newString = nil;
newString = [textField.text stringByAppendingString:string];
NSLog(@"string:%@",string);
NSLog(@"newString:%@",newString);
return YES;
}
我是在storyborad里直接把object框的Text Field拖过来的,应该属于自定义的cell中包含TextField作为元素吧。
哪 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{} 怎样把indexPath传过来啊?我需知道是哪行的TextField改变了。
textField.tag=[indexPath row];
写全部给你看看
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]);
}
ihefe的方法可行,我第一步改为- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
UITextField *field = (UITextField *)[cell viewWithTag:101 + indexPath.row];
[field setText:[NSString stringWithFormat: @"%d",wantSearchThreadList[indexPath.row].threadCount]];
field.delegate = s
[textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];//第二步,实现回调函数
- (void) textFieldDidChange:(id) sender {
UITextField *_field = (UITextField *)sender;
NSLog(@"%@",[_field text]);
}
第2种textField.delegate=self;...
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *newString = nil;
newString = [textField.text stringByAppendingString:string];
NSLog(@"string:%@",string);
NSLog(@"newString:%@",newString);
return YES;
}
我是在storyborad里直接把object框的Text Field拖过来的,应该属于自定义的cell中包含TextField作为元素吧。
哪 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{} 怎样把indexPath传过来啊?我需知道是哪行的TextField改变了。
textField.tag=[indexPath row];
写全部给你看看
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]);
}
ihefe的方法可行,我第一步改为- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
UITextField *field = (UITextField *)[cell viewWithTag:101 + indexPath.row];
[field setText:[NSString stringWithFormat: @"%d",wantSearchThreadList[indexPath.row].threadCount]];
field.delegate = s
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询