2015-01-26

ITable demo – fixed header for UITableView datagrid

Views: 7008 | Add Comments

The table has header row(like th in html) that anchors at the top.

//
//  ITableFixedHeaderDemo.h
//  IKit
//
//  Created by ideawu on 15-1-22.
//  Copyright (c) 2015年 ideawu. All rights reserved.
//

#import "IKit/IKit.h"

@interface ITableFixedHeaderDemo : ITable

@end

//
//  ITableFixedHeaderDemo.m
//  IKit
//
//  Created by ideawu on 15-1-22.
//  Copyright (c) 2015 ideawu. All rights reserved.
//

#import "ITableFixedHeaderDemo.h"

@implementation ITableFixedHeaderDemo

- (id)init{
    self = [super init];
    self.navigationItem.title = @"ITableFixedHeaderDemo";
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];

    {
        ITableRow *headerRow = [[ITableRow alloc] initWithNumberOfColumns:3];
        [headerRow.style set:@"font-weight: bold; text-align: center; background: #6cf;"];
        [headerRow column:0 setText:@"Id"];
        [headerRow column:1 setText:@"Name"];
        [headerRow column:2 setText:@"Age"];
        self.tableHeader = headerRow;
    }
    
    for(int i=0; i<20; i++){
        ITableRow *row = [[ITableRow alloc] initWithNumberOfColumns:3];
        [row.style set:@"text-align: center; border-bottom: 1 solid #eee; background: #fff;"];
        [row column:0 setText:[NSString stringWithFormat:@"%d", i+1]];
        [row column:1 setText:[NSString stringWithFormat:@"name-%d", i+1]];
        [row column:2 setText:[NSString stringWithFormat:@"%d", rand()%50+1]];
        [self addIViewRow:row];
    }
    
    return self;
}

@end
Posted by ideawu at 2015-01-26 11:37:23 Tags: ,

Leave a Comment