【问题标题】:How to save text fields in a custom tableview cell如何在自定义表格视图单元格中保存文本字段
【发布时间】:2014-05-06 21:48:52
【问题描述】:

问题在标题中^^。您如何在自定义 tableView 单元格中保存 2 个文本字段。假装重用标识符不存在(但是有人可以告诉我如何解决这个问题,那就太棒了)。感谢任何可以提供帮助的人。

【问题讨论】:

  • 欢迎来到 Stack Overflow。您所说的“保存”文本字段是什么意思?您的意思是从中存储文本吗?还是插入单元格?请添加更多信息或发布屏幕截图,因为这个问题看起来没有正确提出。添加您的代码也将不胜感激。

标签: ios arrays uitableview tableview textfield


【解决方案1】:

在您的自定义 UITableViewCell 类中,您可以从文本字段数组中添加文本字段。

即,在 viewDidLoad 中,您可以在数组中插入标签 110 和 111 的两个文本字段。

     -(void)viewDidLoad
      {
         arryTextfields = [NSMUtableArray alloc]init];
         for(int i=0;i<2;i++)
         {
            UITextField * textField = [[UITextField alloc]init];
            NSMutableDictionary * dic =[NSMutableDictionary alloc]init]
            [dic setObject:textField forKey:[NSString stringWithFormat:@"11%d",i]];
            [arryTextfields addObject:dic];
            [textField release];
            [dic release];
          }
       } 

在您的 tableview 委托“cellForRowAtIndexPath”中。

              - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath
            {
               static NSString *CellIdentifier = @"Cell";
               YourCustomTableviewCell * cell = [[YourCustomTableviewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

               UITextField * textfield1 = [[cell.arryTextfields objectAtIndex:indexPath.row]objectForKey:@"110"];

                UITextField * textfield2 = [[cell.arryTextfields objectAtIndex:indexPath.row]objectForKey:@"111"];


             return cell;
            }

【讨论】:

  • 所以我现在已经实现了这段代码,但我需要知道如何保存文本字段,以便每个单元格的文本字段显示不同的信息
  • 为什么要保存文本字段。您可以使用文本字段的唯一键将每个文本字段的值保存在字典中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多