我想创建一个具有2个节行的TableView。
该表有2个部分(第一个部分有1个单元格,第二个部分有3个单元格)

注意:第一部分的单元格与第二部分的单元格不同。

这是我的代码,但是不起作用!!!

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

    NSArray *name = [_names objectForKey:key];
    static NSString *CellIdentifier2 = @"CustomerCell";

    if (indexPath.section == 0) {

        static NSString *CellIdentifier = @"myCell";
        FirstCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[FirstCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        // Configure the cell...
        cell.nameLable.text = [NSString stringWithFormat:@"blue"];
        cell.numberLable.text = [NSString stringWithFormat:@"1212432543"];
        cell.profileImage.image = [UIImage imageNamed: @"profile.png"];

        return cell;
//this part not working !!! XD

    }
    else if (indexPath.section >= 1) {

        CustomerCell *cell = (CustomerCell *)[self.table dequeueReusableCellWithIdentifier:CellIdentifier2];
        if (cell == nil)
        {
            NSArray *topLevelObject = [[NSBundle mainBundle] loadNibNamed:@"CustomerCell" owner:nil options:nil];

            for (id currentObject in topLevelObject) {
                if ([currentObject isKindOfClass:[CustomerCell class]]) {
                    cell = (CustomerCell *)currentObject;
                    break;
                }
            }
        }
        // Configure the cell...
        cell.titleLable.text = [name objectAtIndex:indexPath.row];
        return cell;
    }
    return nil;
}


customerCell和FirstCell是自定义单元的UITableViewCell
当我执行此代码时,只有一个部分不起作用,并且不显示单元格,而另一部分正在工作,请指导我并告诉我我的错误在哪里。

最佳答案

尝试这个:

FirstCell *cell = (FirstCell *)[tableView dequeueReusableCellWithIdentifier:strEvalIdentifier];
if (cell == nil)
{
   NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FirstCell" owner:self options:nil];
   cell = [nib objectAtIndex:0];
}

08-06 04:06
查看更多