我正在使用一个使用动态节的tableview,我有一个sectionArray,它由节标题和另一个数组组成,该数组具有所有节的全部数据,
我无法弄清楚如何为每个部分的行写单元格,因为它是动态的

代码是:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  return [appDelegate.sectionArray count];
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
  return [appDelegate.appNameArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"Cell";

  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  UILabel *AppNameLabel=[[UILabel alloc]initWithFrame:CGRectMake(80, 0, 120, 30)];
  [AppNameLabel setBackgroundColor:[UIColor clearColor]];
  [AppNameLabel setText:[NSString stringWithFormat:@"%@",[appDelegate.appNameArray objectAtIndex:indexPath.row]]];
  [AppNameLabel setFont:[UIFont systemFontOfSize:14]];
  [cell.contentView addSubview:AppNameLabel];
  return cell;
}


在appname数组中,我有包含所有部分的数据,我需要为特定部分隔离,如何在单元格中为行索引提供帮助。

提前致谢。

最佳答案

无需为sectionTitle和appName创建两个不同的array。用对象的NSArray创建源NSDictionaryNSDictionary对象包含appName数组为values,sectionTitle为key

sourceArray
(
 dictionaryObject1
 {
 key : sectionTitle,
 value : ( appName1,appName2,appName3)
 },
 dictionaryObject2
 {
 key : sectionTitle,
 value : ( appName1,appName2,appName3)
 },
.
.
.
)

10-07 19:04
查看更多