self.tableView.dataSource = self;
@interface ViewController () <UITableViewDataSource> @end
// 多少組數據 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; // 每一組有多少行數據 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; // 每一行顯示什麼內容 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; // 每一組的頭部 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; // 每一組的尾部 - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
// 設置每一行cell的高度
self.tableView.rowHeight = 100;
// 設置每一組頭部的高度
self.tableView.sectionHeaderHeight = 50;
// 設置每一組尾部的高度
self.tableView.sectionFooterHeight = 50; ——>設置的每一行都是固定的
// 設置分割線顏色
self.tableView.separatorColor = [UIColor redColor];
// 設置分割線樣式
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// 設置表頭控件
self.tableView.tableHeaderView = [[UISwitch alloc] init];
// 設置表尾控件
self.tableView.tableFooterView = [UIButton buttonWithType:UIButtonTypeContactAdd];
// 設置右邊索引文字的顏色
self.tableView.sectionIndexColor = [UIColor redColor];
// 設置右邊索引文字的背景色
self.tableView.sectionIndexBackgroundColor = [UIColor blackColor];
// 設置右邊的指示樣式
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// 設置右邊的指示控件
cell.accessoryView = [[UISwitch alloc] init];
// 設置cell的選中樣式
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// backgroundView優先級 > backgroundColor
// 設置背景色
cell.backgroundColor = [UIColor redColor];
// 設置背景view ——(可自定義背景圖片)
UIView *bg = [[UIView alloc] init];
bg.backgroundColor = [UIColor blueColor];
cell.backgroundView = bg;
// 設置選中的背景view
UIView *selectedBg = [[UIView alloc] init];
selectedBg.backgroundColor = [UIColor purpleColor];
cell.selectedBackgroundView = selectedBg;