tableView的cell中有TextField,怎样在导航离开此view或编辑完TextField时,获得TextField.text的值?

解决方案 »

  1.   

    tableView的cell中有TextField
    究竟是cell作为容器放置了TextField,还是自定义的cell中包含TextField作为元素?
      

  2.   

    UITableViewCell* cell = [self.utvLeft cellForRowAtIndexPath:indexPath];
                        if (cell != nil) 
                        {
                            TextField *field = (TextField*)[cell viewWithTag:CELL_TEXTFIELD];
      

  3.   

    textFieldDelete里面有方法,当你开始编辑时  你可以干某事,当你离开时忙你可以干某事,这个时候,你去想个办法保存你的值就行 我的理解 
      

  4.   

    第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;
    }
      

  5.   


    我是在storyborad里直接把object框的Text Field拖过来的,应该属于自定义的cell中包含TextField作为元素吧。
    哪 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{} 怎样把indexPath传过来啊?我需知道是哪行的TextField改变了。
     
      

  6.   


    textField.tag=[indexPath row];
      

  7.   

    吃饭去。写全部给你看看 
            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]);
    }
      

  8.   

    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 = self;
        [field addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        
        return cell;
    }可执行,只是
    field.delegate = self;
    那句有编译警告:“Passing'ViewController *const _strong' to parameter of incompatible type íd<UITextFieldDelegate>”
      

  9.   

    .h  没引用 UITextFieldDelegate
      

  10.   

    对了,不要
    field.delegate = self;
    就行了。