我是iphone应用程序开发的新手,所以请任何人帮助我。我的主要问题是
- >解析xml后我在nsarray中插入xml的属性值,其中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的每个单元格中逐个显示每个属性值。但是我不知道section方法中的行数是多少。请任何正文帮助我。我正在给出示例代码....
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section{
NSLog(@"The number of row in the object array: %d ",[records count]);
return [records count];
}
tableview方法就在这里......现在告诉我在每个单元格中逐个显示所有属性值的返回类型。
先谢谢。
答案 0 :(得分: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;
}
...
当然,你需要为每个字段的大小和屏幕上的总长度工作。