0

我正在项目中有很多形式(如注册表格)大约20-25forms在那里,每个窗体都有8-9输入框即textfields。在UITableViewCell中的文本获取当用户滚动时删除uitableview

1)我已创建自定义的UITableViewCell 2)I在指数为行小区i写以下代码:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

     if(indexPath.row==0){ 
      NSString *simpleTableIdentifier = @"cell"; 
      customcell *cell = (DropdownCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
      if (cell == nil) 
      { 
       NSArray *nib = [[NSBundle mainBundle] loadNibNamed:customcell owner:self options:nil]; 
       cell = [nib objectAtIndex:0]; 
      } 
      cell.Txtlist.placeholder = @"Select type of meeting"; 
      self.txtType1 = cell.Txtlist; // i had created the local variable uitextfield.So that i can access that locally in my application. 
      cell.selectionStyle = UITableViewCellSelectionStyleNone; 
      return cell; 
     } 
     else if(indexPath.row == 1){ 
      NSString *simpleTableIdentifier = cell; 
      customcell *cell = (customcell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
      if (cell == nil) 
      { 
       NSArray *nib = [[NSBundle mainBundle] loadNibNamed:customcell owner:self options:nil]; 
       cell = [nib objectAtIndex:0]; 
      } 
      cell.Txtlist.placeholder = @"Select Client Name"; 
      self.txtType2 = cell.Txtlist; // i had created the local variable uitextfield.So that i can access that locally in my application. 
      cell.selectionStyle = UITableViewCellSelectionStyleNone; 
      return cell; 
     } 
} 

3)UI是否合适。 但问题是,当我在行= 0的文本字段中写入一些文本并滚动uitableview。 textfield的值得到删除。

我该如何解决这个问题。 请帮忙。 也帮助我,如果有更好的方法来实现窗体。

谢谢

回答

0

你是不是正确重用表格视图单元。 阅读documentation一次。

+0

谢谢你的快速回复。你能帮我指出一个确切的错误吗? –

1

根据我的理解,你在单个页面上使用4-5文本字段,那么你必须将这些值存储在数组或字典中的某个位置,以便每当调用cellForRowAtIndex时,该单元格将使用该单元格该数组或字典显示给以前填充的数据。 或者“只需存储值”即可。

0
  1. 初始化全局NSMutableDictionary对象。

    //在标题中 NSMutableDictionary * values;

  2. 字典的用户价值特征。

    // in view-did-load method values = [NSMutableDictionary dictionary];

    //设置给定的文本值为 [values setValue:@“”forKey:@(0)]; //你的行索引0 [values setValue:@“”forKey:@(1)]; // index 1

  3. 设置TextField委托&标签,还设置存储文本。

    cell.Txtlist.delegate = self; cell.Txtlist.tag = indexPath.row; NSString * value = values [@(indexPath.row)]; cell.Txtlist.text = value;

  4. 实现的TextField方法,

    • (无效)textFieldDidEndEditing:(的UITextField *)的TextField { [值的setValue:的TextField.text forKey:@(textField.tag)]; }

享受...

相关问题