IOS第七天(4:UiTableView 数据的显示优化重复实例和tableFooterView和tableHeaderView)

//加上头部 和底部

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self tableView];
    
    // 设置行高
    self.tableView.rowHeight = 120;
    
    // 分隔线
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    /**
     32位真彩色 ARGB 2^8 * 2^8 * 2^8 * 2^8 = 2^32 = 2^2 * 2^10 * 2^10 * 2^10  = 4G
     2^64 = 16 GG
     
     A = Alpha
     R
     G
     B
     24位真彩色 RGB 2^8 * 2^8 * 2^8 = 2 ^ 24 = 2^4 * 2^10 = 16 * 100万
     R = Red     1个字节  8位 0~255
     G = Green
     B = Blun
     
     # ff ff ff ff
     */
    self.tableView.separatorColor = [UIColor colorWithWhite:0.0 alpha:0.2];
    
    // headView,放在tableView最顶部的视图,通常用来放图片轮播器
    UIView *head = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 130)];
    head.backgroundColor = [UIColor blueColor];
    self.tableView.tableHeaderView = head;
    
    // footerView,通常做上拉刷新
    UIView *foot = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    foot.backgroundColor = [UIColor redColor];
    self.tableView.tableFooterView = foot;
}

//优化 cell 复用view

 // 0. 可重用标示符字符串
    // static静态变量,能够保证系统为变量在内存中只分配一次内存空间
    // 静态变量,一旦创建,就不会被释放,只有当应用程序被销毁时,才会释放!
    static NSString *ID = @"Cell";
    
    // 1. 取缓存池查找可重用的单元格
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    // 2. 如果没有找到
    if (cell == nil) {
        NSLog(@"实例化单元格");
        // 创建单元格,并设置cell有共性的属性
        
        // 实例化新的单元格
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
        
        // 右侧箭头
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        // 背景颜色,会影响到未选中表格行的标签背景
//        cell.backgroundColor = [UIColor redColor];
        // 在实际开发中,使用背景视图的情况比较多
        // 背景视图,不需要指定大小,cell会根据自身的尺寸,自动填充调整背景视图的显示
//        UIImage *bgImage = [UIImage imageNamed:@"img_01"];
//        cell.backgroundView = [[UIImageView alloc] initWithImage:bgImage];
//        UIView *bgView = [[UIView alloc] init];
//        bgView.backgroundColor = [UIColor yellowColor];
//        cell.backgroundView = bgView;
        // 没有选中的背景颜色
        // 选中的背景视图
//        UIImage *selectedBGImage = [UIImage imageNamed:@"img_02"];
//        cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:selectedBGImage];
    }

 

posted @ 2015-08-05 14:03  iso  阅读(717)  评论(0编辑  收藏  举报