- 表视图由头部,尾部视图,中间由一连串单元格视图组成。
- 表视图头部由tableHeaderView属性设置,尾部视图通过tableFooterView属性设置。
- 分组表格由一连串section视图组成,每个section又包含一个连续的单元格
- 每个section视图也有头部视图和尾部视图,通过委托方法设置。
1. .h 文件要声明协议
<UITableViewDataSource>
@property (nonatomic,retain)NSArray *listArray;//tableView的数据集合
3..h中声明变量
@private
UITableView *_tableView;
4.实例化变量
_tableView = [[UITableViewalloc] initWithFrame:self.view.boundsstyle:UITableViewStylePlain];
//得到字体所有样式
self.listArray = [UIFontfamilyNames];
//实现数据源方法
_tableView.dataSource =self;
[self.viewaddSubview:_tableView];
5.覆盖delegate方法
#pragma mark - tableView 的数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.listArraycount];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier =@"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier];
}
NSString *fontName = self.listArray[indexPath.row];
cell.textLabel.text = fontName;
cell.textLabel.font = [UIFontfontWithName:fontName size:14];
return cell;
}