首页 > 移动平台 > 详细

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

时间:2015-08-05 12:44:14      阅读:186      评论:0      收藏:0      [点我收藏+]

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

 

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

原文:http://www.cnblogs.com/happyplane/p/4704293.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!