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;
    }
}

 

posted @ 2015-08-05 11:42  HappyPlane  阅读(904)  评论(0编辑  收藏  举报