2011-10-19 24 views
0

我是較新的到iPhone應用程序的開發,所以請人幫助me.my主要問題是UITableView顯示xml解析數據的行數是多少?

- >解析我在其中的NSArray是nsmutable陣列的對象的的NSArray插入XML的屬性值的XML之後。類似的東西...

[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.but的每一個細胞都顯示每個屬性值一個輪空一個我不知道會是怎樣的行數在一節method.please任何身體幫我,我給我的示例代碼....

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

實現代碼如下方法就在這裏......現在告訴我,這將是對每一個細胞都顯示所有的屬性值一個輪空一個返回類型。

在此先感謝。

回答

0

你可以爲每個字段創建一個標籤,並把它添加到細胞中的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; 
} 

... 

當然你需要工作每個字段的大小和總長度屏幕。