Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective-C剖视图_Objective C_Uitableview_Sections - Fatal编程技术网

Objective-C剖视图

Objective-C剖视图,objective-c,uitableview,sections,Objective C,Uitableview,Sections,我想要一个分区的UITableView,但我不知道如何,我的情况是: 我有两个数组 阵列日期(“2013年8月12日”、“2013年8月13日”、“2013年8月17日”) 数组计数(“2”、“1”、“5”) 计数表示节中有多少行 我有 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return [dateArray objectAtIndex:secti

我想要一个分区的UITableView,但我不知道如何,我的情况是:

我有两个数组

阵列日期(“2013年8月12日”、“2013年8月13日”、“2013年8月17日”) 数组计数(“2”、“1”、“5”)

计数表示节中有多少行

我有

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [dateArray objectAtIndex:section];
}
但如何才能使在第一节,第二节2行1行和第三节5行

我希望有人能帮助我。如果你有问题就问

谢谢


编辑:我从我的网站获取信息,因此数组每天都在变化。

您需要覆盖以下UITableView数据源方法:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  if (section == 0)
    return 2
  else if (section == 1)
    return 1
  else (section == 2)
    return 5
}
更新:从您的评论来看,您似乎有一个“平面”数据源阵列。 由于每个部分中的行号都以零开始,因此必须计算 从前面所有节的行号和节数索引到数组中 在
单元格中,按行索引路径

NSInteger flatIndex = indexPath.row;
for (NSInteger sec = 0; sec < indexPath.section; sec++)
    flatIndex += [tableView numberOfRowsInSection:sec];

cell.textLabel.text = yourFlatDataArray[flatIndex]; // (Just an example!)
NSInteger flatIndex=indexath.row;
对于(NSInteger sec=0;sec
返回
NumberOfSectionsTableView:

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
      return [self.countArray count];
 }
然后从数组中获取数字,并将其返回到
numberofrowsin部分:

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section            
 {
      NSNumber *count = [self.countArray objectAtIndex:section];

      return [count integerValue];
 }

谢谢,但我从网站上获取信息,因此阵列是动态的,每天都在变化。那么如何使其动态化呢?已经有一个数组存储每个节的行数,您不需要硬编码,只需返回从该数组中获取的数字。谢谢,它几乎可以工作,但现在我在每个部分中都有相同的行,但是当第一部分有2行时,我希望第二部分计数进一步,因此3和4,而不是1和2。我希望你能理解this@HenkdeBoer:那么您对
cellForRowAtIndexPath
的实现不正确。必须同时使用
indexPath.section
indexPath.row
来显示元素。在每个节中,行号以零开始。
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section            
 {
      NSNumber *count = [self.countArray objectAtIndex:section];

      return [count integerValue];
 }