【问题标题】:Retrieving the data from the table in iphone从iphone中的表中检索数据
【发布时间】:2012-02-14 18:38:09
【问题描述】:

我有一个表,其中每一行都包含一个文本字段。在我在所有作为文本字段的行中输入文本后,我想将数据检索到一个数组中。谁能告诉我从每一行检索数据的想法是文本字段吗?

【问题讨论】:

    标签: xcode uitableview nsmutablearray uitextfield


    【解决方案1】:

    我无法相信你。语法不好,没有研究。

    要获得所有文本字段的数组,我会这样做:

    NSArray *subviews = self.view.subviews;
    NSMutableArray *textFelds = [[NSMutableArray alloc]init];
    NSMutableArray *indexPaths = [[NSMutableArray alloc]init];
    
    
    NSObject *obj;
    

    for(子视图中的 obj){ if ([obj 类] == [UITextField 类]) { [文本字段添加对象:obj]; CGPoint 位置 = obj.center; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location]; [indexPaths addObject:indexPath]; } }

    它首先获取主视图的所有子视图,然后确定它们是否是文本字段。如果它们是 textFields,它会将其添加到数组并获取 indexPath。

    希望我已经回答了你的问题

    【讨论】:

      【解决方案2】:

      您有详细信息,例如,哪一行有文本字段,哪一行没有。

      您可以通过使用两个不同的单元王来获得此功能

          static NSString *CellIdentifierNormal = @"Cell";
          static NSString *CellIdentifierTF = @"Cell";
          UITableViewCell *cell;
          if(indexPath.row %2 == 0){ //Example
              cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifierNormal];    
              if (cell == nil) {
                  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifierNormal] autorelease];
          }
          } else {
              cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifierTF] autorelease];    
      TF *tf = [[TF alloc] init];
      tf.tag = 10;
          }
      

      在文本字段行的情况下,不应该使用dequeueReusableCellWithIdentifier它重新使用现有的单元格,这样文本字段数据可能会损坏[当您的数据行大小大于表格大小-高度时会发生这种情况]

      当你想从 TF 收集数据时

      只需使用表格中的行数运行循环,并检查与创建单元格相同的条件。

      访问单元格,单元格中的TF使用TF中的标签号[10]获取文本

      【讨论】:

        猜你喜欢
        • 2011-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-07
        • 1970-01-01
        相关资源
        最近更新 更多