从 iPhone 中的表中检索数据

发布于 2024-12-28 00:34:49 字数 88 浏览 3 评论 0原文

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

I have a table wherein every row contains a textfield.After i entertext in all the rows which are text fields i want to retrieve the data into an array.Can any one tell me the idea of retrieving the data from every row which are textfields?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一袭白衣梦中忆 2025-01-04 00:34:49

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

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

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


NSObject *obj;

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

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

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

I cannot believe you. Bad grammar and no research.

To get an array of all text fields, I would do:

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];
}
}

It first gets all of the subviews of the main view, then determines if they are text fields. If they are textFields, it adds that to an array and also gets the indexPath.

I hope I have answered your question

陌伤ぢ 2025-01-04 00:34:49

您拥有诸如哪一行有文本字段、哪一行没有文本字段之类的详细信息。

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

    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 获取文本

You are having the details like, which row has text fields, which are not.

You can get this feature by using two different king of cells

    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;
    }

In Text field row case, should not use the dequeueReusableCellWithIdentifier it re uses the existing cells, so that the text fields data may corrupt [This will happen when your data rows size greater than the table size - height]

Whenever you want collect the data from TF's

Just run loop with number of rows in table, and check same condition as you are using in creating cell.

Access the cell, and TF from cell by using tag number [10] from TF get the text

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文