iOS 在一个TableView内使用不同的Cell

通过Identifier标记不同的Cell,实现不同Cell的重用:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row % 2) 
    {
        static NSString *ID1 = @"CellA";
       
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID1];
       
        if (!cell)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID1];
        }
       
        cell.textLabel.text = @"A";
       
        return cell;
    }
    else
    {
        static NSString *ID2 = @"CellB";
       
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID2];
       
        if (!cell)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID2];
        }
       
        cell.textLabel.text = @"B";
       
        return cell;
    }
}
原文地址:https://www.cnblogs.com/happyplane/p/4704293.html