1.tableView展示数据的过程
调用数据源的下面方法得知一共有多少组数据
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
调用数据源的下面方法得知每一组有多少行数据
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
调用数据源的下面方法得知每一行显示什么内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
调用数据源的下面方法得知每一组有多少行数据
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
调用数据源的下面方法得知每一行显示什么内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
2.实例
//
// MJViewController.m
#import "MJViewController.h"
@interface MJViewController () <UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end
@implementation MJViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 32bit颜色 : ARGB
// Alpha : 8
// Red : 8
// Green : 8
// Blue : 8
// 24bit颜色 : RGB
// Red : 8
// Green : 8
// Blue : 8
// #ff ff ff 白色
// #00 00 00 黑色
// #ff 00 00 红色
// # ff ff 00
// #ff ff ff ff
// 每一个颜色通道占据8个二进制位
// 每一个颜色通道的取值范围是[0, 255]
// R 78
// G 100
// B 255
// # ff ff 00 ff
self.tableView.separatorColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:0 alpha:255/255.0];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// 表格的头部控件(直接显示表格的最顶部)
self.tableView.tableHeaderView = [UIButton buttonWithType:UIButtonTypeContactAdd];
self.tableView.tableFooterView = [[UISwitch alloc] init];
}
- (BOOL)prefersStatusBarHidden
{
return YES;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text = [NSString stringWithFormat:@"第%d行数据", indexPath.row];
return cell;
}
@end
3.运行结果
tableHeaderView属性
tableFooterView属性