【问题标题】:Multiple sections array in tableview表格视图中的多个部分数组
【发布时间】:2012-08-06 12:30:12
【问题描述】:

首先我想说我有一个类似的帖子,但有些帖子是如何消失的,所以如果它再次出现,我无意重复发布。

我创建了一个包含 3 个部分的 uitableview,并从 3 个不同的数组中填充

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{ //去掉这里的一堆代码,让它更短

switch (indexPath.section) {
    case 0:
        cell.textLabel.text=[DogArray objectAtIndex:indexPath.row];
        break;
     case 1:
        cell.textLabel.text=[BirdArray objectAtIndex:indexPath.row];
        break;
    case 2:
        cell.textLabel.text=[FishArray objectAtIndex:indexPath.row];
       break;
    default:
        break;
}




[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;

}

这三个部分中的每一个都从各自的数组中获取自己的值。

唯一的问题是。在我使用一个数组之前,我会这样分配

 (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


if (checInt==0) 
{ 
    ThridView *summary=[[ThridView alloc]init];
    summary.detailViewController = detailViewController;
    self.detailViewController.receivedRainObject = [MainArray objectAtIndex:indexPath.row];//Pay attention to this line

这会将斗牛犬、鸽子或箭鱼传递给摘要,基于每个人是 .row.... 不幸的是我不能再这样做了,因为我使用了三个不同的数组。我正在考虑使用开关,但即使我从鱼阵列中选择箭鱼。 NSLOG([DogArray objectAtIndex:indexPath.row]) 向我展示了比特犬 和 NSLOG([BirdArray objectAtIndex:indexPath.row]) 向我展示了鸽子 所以我不能说这两个是空的。

我也很想知道一种方法,即使它们来自不同的数组,我仍然可以传递我选择的每种动物,谢谢

【问题讨论】:

  • 将数组传入tableView中 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{} 方法
  • 我已经在其中传递了所有 3 个数组
  • 那么,在你的程序中什么是行不通的。

标签: xcode uitableview sections


【解决方案1】:

在我看来,它应该与您用于将文本放入单元格的逻辑相同。也就是说,您的索引路径的部分选择数组,行选择偏移量。

【讨论】:

  • 是的,谢谢,我只是使用与填充文本相同的大小写
猜你喜欢
  • 1970-01-01
  • 2014-02-18
  • 2019-10-03
  • 1970-01-01
  • 1970-01-01
  • 2017-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多