从iphone中的表中检索数据

时间:2012-01-20 05:56:23

标签: xcode uitableview nsmutablearray uitextfield

我有一个表格,其中每一行都包含一个文本字段。我在所有文本字段的行中输入后我想将数据检索到一个数组中。任何人都可以告诉我从每一行检索数据的想法是文本字段吗?

2 个答案:

答案 0 :(得分:1)

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

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

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


NSObject *obj;

for(obj in subviews){         if([obj class] == [UITextField class]){             [textFields addObject:obj];             CGPoint location = obj.center; NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];             [indexPaths addObject:indexPath];          }     }

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

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

答案 1 :(得分:1)

您正在获取详细信息,例如哪一​​行包含文本字段,而不是。

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

    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的标签号[10]从小区访问单元格和TF获取文本

相关问题