滚动tableview时隐藏文本字段数据

时间:2017-01-05 09:19:42

标签: ios uitableview uitextfield

我正在开发IOS App。在tableviewcell上添加多个文本字段。当在texfield上输入数据时,滚动tableview文本字段数据隐藏。如何在tableview上管理textfield。请帮助我并提前致谢enter image description here

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableViews{
    // Return the number of sections.
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    // Return the number of rows in the section.
    return 100;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *MyIdentifier = @"cell";
    UITableViewCell *cell;
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:MyIdentifier];

    }
    UITextField *textFieldName = [[UITextField alloc]initWithFrame:CGRectMake(8.0f, 3.0f, 80.0f, 36.0f)];
    [cell addSubview:textFieldName];
    [textFieldName setDelegate:self];
    textFieldName.tag = indexPath.row+1;

    UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake(96.0f, 0.0f, 1.0f, 50.0f)];
    line.backgroundColor = [UIColor colorWithRed:214.0/255.0 green:214.0/255.0 blue:214.0/255.0 alpha:1.0];
    [cell addSubview:line];

    [cell setSeparatorInset:UIEdgeInsetsZero];
    tableView.allowsSelection=NO;
    return cell;
}

-(void)textFieldDidEndEditing:(UITextField *)textField{

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:([textField tag]-1) inSection:0];
    UITableViewCell *Cell = [_dairyTable cellForRowAtIndexPath:indexPath];

}

1 个答案:

答案 0 :(得分:0)

如何处理UITextField中的UITableView值:

  1. 首先,您必须创建可变数组,其计数等于UITextField的数量。

  2. cellForRow执行cell.textField.tag = indexPath.row,您可以识别每个UItextField

  3. 每个字符更改时,以相同的顺序保存数组中的每个UITextField值。因此,通过将textdidChange标记为UITextField来识别UITextfield textfield.tag委托方法中的代码。

  4. 每当用户输入或编辑文本时,您都会在数组中获得该文本。

  5. 现在在cellForRow添加以下行:
  6. cell.textfiled.text = arrDataText[index.row]

相关问题