首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

UITableView使用方法(3) - 交替颜色单元格的实现

2012-08-30 
UITableView使用方法(三) - 交替颜色单元格的实现效果如下:主要是在tableView的cellForRowAtIndexPath中实

UITableView使用方法(三) - 交替颜色单元格的实现


效果如下:

UITableView使用方法(3) - 交替颜色单元格的实现
























主要是在tableView的cellForRowAtIndexPath中实现,实现代码如下:

- (UITableViewCell *) tableView:(UITableView *)tableView          cellForRowAtIndexPath:(NSIndexPath *)indexPath{           NSString *tag=@"tag";    CGSize size;    CGFloat actualSize;        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tag];        if (cell==nil ) {        cell=[[[ UITableViewCell alloc ]                initWithStyle:UITableViewCellStyleSubtitle               reuseIdentifier:tag] autorelease];            }            NSUInteger row=[indexPath row];         //设置文本    cell.textLabel.text = [listData objectAtIndex :row];        //---------------------    //设置颜色交替    if( (row%2) ==0)        cell.backgroundColor = [UIColor whiteColor];    else        cell.backgroundColor = [UIColor lightGrayColor];    //---------------------        cell.detailTextLabel.text = [listData objectAtIndex :row];        return cell;}

比较简单,就是改变不同行的背景就行了。


运行环境:

MacOS 10.7.4 + XCode 4.3.3 + iOS 5.1


热点排行