【问题标题】:what will be the number of rows for UITableView for displaying the xml parsed data?用于显示 xml 解析数据的 UITableView 的行数是多少?
【发布时间】:2011-10-19 06:14:10
【问题描述】:

我是 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 方法在这里...现在告诉我在每个单元格中逐一显示所有属性值的返回类型是什么。

提前致谢。

【问题讨论】:

    标签: xml uitableview nsarray


    【解决方案1】:

    您可以为每个字段创建一个标签并将其添加到 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;
    }
    
    ...
    

    当然,您需要确定每个字段的大小和屏幕中的总长度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-11
      • 2015-02-03
      • 1970-01-01
      • 2019-09-21
      • 2018-01-11
      • 1970-01-01
      相关资源
      最近更新 更多