UITableView的兩種樣式
UITableViewStylePlain 不分組顯示
UITableViewStyleGrouped 分組顯示
UITableViewDataSource //數據源協議緩存
兩個必需實現的方法
//一組有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//每一行顯示什麼內容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
// 設置分隔線顏色
self.tableView.separatorColor = [UIColor colorWithRed:35/255.0 green:136/255.0 blue:255/255.0 alpha:119/255.0];
// 設置分隔線style
// self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// tableHeaderView廣告位
self.tableView.tableHeaderView = [[UISwitch alloc] init];
// 加載更多
self.tableView.tableFooterView = [UIButton buttonWithType:UIButtonTypeContactAdd];
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
static NSString *ID = @"mjcell";spa
// 2.從緩存池中取出cellit
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];io
// 3.若是緩存池中沒有celltable
if (cell == nil) {queue
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];方法
}數據
// 4.設置cell的屬性...協議
return cell;
點擊每行單元格中的cell顯示什麼內容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath