简体   繁体   English

如何在自定义表格视图单元格中保存文本字段

[英]How to save text fields in a custom tableview cell

Question is in the title ^^. 问题在标题^^中。 How do you go about saving say 2 textFields in a custom tableView cell. 如何在自定义tableView单元格中保存说2个textFields。 Pretend the reuse identifier doesn't exist (however is someone could show me how to get around that then that would be awesome). 假设重用标识符不存在(但是有人可以向我展示如何解决这个问题,那真是太棒了)。 Thanks for anyone that can help. 感谢任何可以提供帮助的人。

In your custom UITableViewCell class you can add textfields from an array of textfields. 在您的自定义UITableViewCell类中,可以从文本字段数组中添加文本字段。

ie, in the viewDidLoad you can insert two textfields of tag 110 and 111 in an array. 即,在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];
          }
       } 

In your tableview delegate "cellForRowAtIndexPath". 在您的表视图中委托“ 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;
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM