UITableView 用于显示 xml 解析数据的行数是多少?

发布于 2024-12-11 00:20:11 字数 1632 浏览 0 评论 0原文

我是 iPhone 应用程序开发新手,所以请任何人帮助我。我的主要问题是

--> 解析 xml 后,我将 xml 的属性值插入 nsarray 中,其中 nsarray 是 nsmutable 数组的对象。类似的东西...

[records addObject:[NSArray arrayWithObjects:
                            [TBXML textForElement:visitor],
                            [TBXML textForElement:uniqueVisitor],
                            [TBXML textForElement:order],
                            [TBXML textForElement:revenue],
                            [TBXML textForElement:conversionRate],
                            [TBXML textForElement:newProduct],
                            [TBXML textForElement:outOfStockProduct],
                            [TBXML textForElement:productInCart],
                            [TBXML textForElement:visitorInc],
                            [TBXML textForElement:uniqueVisitorInc],
                            [TBXML textForElement:orderInc],
                            [TBXML textForElement:revenueInc],
                            [TBXML textForElement:conversionRateInc],
                            [TBXML textForElement:newProductInc],
                            [TBXML textForElement:outOfStockProductInc],
                            [TBXML textForElement:productInCartInc],nil]]; 

现在我想在 uitableview 的每个单元格中逐一显示每个属性值。但我不知道节方法中的行数是多少。请任何人帮助我。我正在给示例代码...

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:    (NSInteger)section{
    NSLog(@"The number of row in the object array:  %d ",[records count]);
return [records count];
    }

tableview 方法在这里...现在告诉我在每个单元格中一一显示所有属性值的返回类型是什么。

提前致谢。

i am newer to iphone application development so please anybody help me.my main problem is

-->after parsed the xml i am inserting attribute value of the xml in a nsarray which nsarray is an object of nsmutable array. something like that...

[records addObject:[NSArray arrayWithObjects:
                            [TBXML textForElement:visitor],
                            [TBXML textForElement:uniqueVisitor],
                            [TBXML textForElement:order],
                            [TBXML textForElement:revenue],
                            [TBXML textForElement:conversionRate],
                            [TBXML textForElement:newProduct],
                            [TBXML textForElement:outOfStockProduct],
                            [TBXML textForElement:productInCart],
                            [TBXML textForElement:visitorInc],
                            [TBXML textForElement:uniqueVisitorInc],
                            [TBXML textForElement:orderInc],
                            [TBXML textForElement:revenueInc],
                            [TBXML textForElement:conversionRateInc],
                            [TBXML textForElement:newProductInc],
                            [TBXML textForElement:outOfStockProductInc],
                            [TBXML textForElement:productInCartInc],nil]]; 

now i want to display each attribute value one bye one in every cell of the uitableview.but i do not know what will be the number of rows in a section method.please any body help me.i am giving the sample code....

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:    (NSInteger)section{
    NSLog(@"The number of row in the object array:  %d ",[records count]);
return [records count];
    }

tableview method is here...now tell me what will be the return type for displaying all the attribute value one bye one in every cell.

Thanks in Advance.

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

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

发布评论

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

评论(1

情痴 2024-12-18 00:20:11

您可以为每个字段创建一个标签,并将其添加到 cellForRowAtIndexPath 中的单元格中,轮廓为:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellPortrait";
UITableviewCell *cell;

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

// THIS CREATES THE CELL
NSInteger index = (page-1)*pagesize + indexPath.row;
NSDictionary* dataAtIndex = [records getDataAtIndex:index];
if (cell == nil) {
    cell = [[[myTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                   reuseIdentifier:CellIdentifier] autorelease];

    int x = 0;
    int cellsize = 50;
    int padding = 1;
    int nbxmlrecords = [[records objectAtIndex:indexPath.row] count];

    for (int idx = 0 ; idx < nbxmlrecords; idx++)
    {
            UILabel* aLabel = [[[UILabel alloc] initWithFrame:CGRectMake(x, 0.0,
                                                                         cellsize, cell.contentView.frame.size.height)] autorelease];
            x = x + cellsize + padding;

            aLabel.tag = idx;
            aLabel.font = [UIFont systemFontOfSize:10.0];
            aLabel.textAlignment = UITextAlignmentLeft;
            aLabel.textColor = [UIColor blackColor];
            aLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight;
            aLabel.opaque = true;

            [cell.contentView addSubview:aLabel];
    }
}

// THIS FILLS THE DATA IN THE CELL
for (int idx = 0 ; idx < nbxmlrecords; idx++)
{
        NSString* value = [[records objectAtIndex:indexPath.row] objectAtIndex:idx];
        UILabel* aLabel = (UILabel *)[cell.contentView viewWithTag:idx];
        aLabel.text = value;
}

...

当然,您需要计算每个字段的大小以及屏幕中的总长度。

You could create a label for each field and add it to the cell in cellForRowAtIndexPath, the outline being :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellPortrait";
UITableviewCell *cell;

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

// THIS CREATES THE CELL
NSInteger index = (page-1)*pagesize + indexPath.row;
NSDictionary* dataAtIndex = [records getDataAtIndex:index];
if (cell == nil) {
    cell = [[[myTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                   reuseIdentifier:CellIdentifier] autorelease];

    int x = 0;
    int cellsize = 50;
    int padding = 1;
    int nbxmlrecords = [[records objectAtIndex:indexPath.row] count];

    for (int idx = 0 ; idx < nbxmlrecords; idx++)
    {
            UILabel* aLabel = [[[UILabel alloc] initWithFrame:CGRectMake(x, 0.0,
                                                                         cellsize, cell.contentView.frame.size.height)] autorelease];
            x = x + cellsize + padding;

            aLabel.tag = idx;
            aLabel.font = [UIFont systemFontOfSize:10.0];
            aLabel.textAlignment = UITextAlignmentLeft;
            aLabel.textColor = [UIColor blackColor];
            aLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight;
            aLabel.opaque = true;

            [cell.contentView addSubview:aLabel];
    }
}

// THIS FILLS THE DATA IN THE CELL
for (int idx = 0 ; idx < nbxmlrecords; idx++)
{
        NSString* value = [[records objectAtIndex:indexPath.row] objectAtIndex:idx];
        UILabel* aLabel = (UILabel *)[cell.contentView viewWithTag:idx];
        aLabel.text = value;
}

...

Of course you'll need to work the size for each field and the total length in the screen.

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