Ios UITableView具有不同格式的单元格&;同一表节中的行为

Ios UITableView具有不同格式的单元格&;同一表节中的行为,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个有一个部分的可编辑视图。该部分中的所有单元格都具有从名为PLContactCell的UITableViewCell子类派生的单元格 我想做的是,对于表格的最后一行,不要使用PLContactCell。我只想使用一个普通的UITableViewCell,我可以按照自己的意愿进行格式化。我也希望这个手机对被窃听没有反应 我的初始cellForRowAtIndexPath方法是: - (UITableViewCell *)tableView:(UITableView *)tableView c

我有一个有一个部分的可编辑视图。该部分中的所有单元格都具有从名为PLContactCell的UITableViewCell子类派生的单元格

我想做的是,对于表格的最后一行,不要使用PLContactCell。我只想使用一个普通的UITableViewCell,我可以按照自己的意愿进行格式化。我也希望这个手机对被窃听没有反应

我的初始cellForRowAtIndexPath方法是:

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

PLContactCell *cell = [tableView dequeueReusableCellWithIdentifier:[PLContactCell   reuseIdentifier]];

  if (!cell) {
      cell = [PLContactCell reusableCell];
      cell.delegate = self;
  }

  id modelObject = [[sections objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];

  if ([modelObject isKindOfClass:[NSString class]]) {
    [cell configureWithString:modelObject];
  } else {
      [cell configureWithUser:modelObject];
  }

  return cell;
}
编辑 因此,我尝试在XIB文件中创建一个UITableView单元,并在其中添加了重用标识符“newCell”。然后我添加了以下代码:

if (indexPath.row == [[sections objectAtIndex:indexPath.section] count] - 1) {
         NSString *CellIdentifier = @"newCell";
         noFormatCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}

这没什么用。我的问题是,我如何访问该段的最后一行,以及如何使该单元格不是一个PrCaltCype,而是一个UITababVIEW单元。

< P>如果它总是在末尾,您可以考虑使用UITababVIEW的页脚视图。然后,您可以在UITableViewDataSource中保留一些额外的逻辑

如果必须将其作为单元格,则必须在最后一节中添加额外的行数,然后在-tableView:cellForRowAtIndexPath:implementation中执行If语句检查以注意它。我强烈建议你尝试页脚法,因为它更干净,更容易弄清楚几个月/几年后你在做什么

这里有一些代码。注意:如果在UITableView中使用分组样式,则需要创建另一个部分

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   if (section == sections.count - 1)  //Looking for last section
   {
      return [sections objectAtIndex:section].count + 1; //Add one to the last section
   }

   return [sections objectAtIndex:section].count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   NSInteger row = indexPath.row;


   if ((sections.count == indexPath.section) && [sections objectAtIndex:indexPath.section].count == indexPath.row)
   {
       //Here you would create and return your UITableViewCell
   }

PLContactCell *cell = [tableView dequeueReusableCellWithIdentifier:[PLContactCell   reuseIdentifier]];

  if (!cell) {
      cell = [PLContactCell reusableCell];
      cell.delegate = self;
  }

  id modelObject = [[sections objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];

  if ([modelObject isKindOfClass:[NSString class]]) {
    [cell configureWithString:modelObject];
  } else {
      [cell configureWithUser:modelObject];
  }

  return cell;
}

你有什么特别的问题吗?也许在
cellforrowatinexpath:
的开头,你可以将(indexPath.row+1)与[tableView numberofrowInstition:indexPath.section]进行比较,这样你就知道你是否在最后一个单元格。如果是这样,打另一个电话。但是考虑德里克的回答似乎就是你need@TimothyMoose:我的问题是,如何访问节的最后一行,以及如何使该单元格不是PLContactCell而是UITableView单元格。您能否澄清“这没有任何作用”?例如,是否输入条件块?如果你能完整地包含你的更新
cellforrowatinexpath
,那会很有帮助。是的,我更喜欢做页脚,但我不负责这个项目,显然它需要一个单元格。现在我有:if(indexath.row=[[sections objectAtIndex:indexath.section]count]-1{NSString*CellIdentifier=@“newCell”;noFormatCell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];},但这不起任何作用。我在nib中创建了一个具有该单元标识符的单元-我不知道如何对其进行编码。