Tableview中的两个不同单元格

时间:2014-03-19 09:23:33

标签: ios objective-c arrays uitableview

这是我的pList。根数组名称是mainList:

enter image description here

我想看看@" BankaAdi"和@" Urun"(在taksitler数组中)在我的tableview中。

我想我应该创建第二个Cell来写@" Urun"因为我的主要单元只写@" BankaAdi"使用此代码:

cell.textLabel.text = 
    [[mainList objectAtIndex:indexPath.row] objectForKey:@"BankaAdi"];

我怎样才能看到我的@" Urun"我的tableview中的字符串?

1 个答案:

答案 0 :(得分:0)

根据我的理解,您需要的是一个包含两个不同部分的表格。因此,在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath中,您需要根据部分设置您的单元格。

以下是它的样子:

- (NSInteger)numberOfRowsInSection:(NSInteger)section
{
  if (section == 1)
  {
     // for first part
     return array1.length;
  }
  else
  {
     // for second part
     return array2.length;
  }
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  return 2;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  UITableViewCell cell = nil;
  if (indexPath.section == 0)
  {
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1 forIndexPath:indexPath];
    cell.textLabel.text = [[mainList objectAtIndex:indexPath.row] objectForKey:@"Adi"];
    cell.detailTextLabel.text= [NSString stringWithFormat:@"%.2f TL",[[[mainList objectAtIndex:indexPath.row] objectForKey:@"dAdi"] floatValue]];
  }
  else
  {
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2 forIndexPath:indexPath];
    cell.textLabel.text = [[mainList objectAtIndex:indexPath.row] objectForKey:@"Adi"];
    cell.detailTextLabel.text= [NSString stringWithFormat:@"%.2f TL",[[[mainList objectAtIndex:indexPath.row] objectForKey:@"dAdi"] floatValue]];
  }
  return cell;
}