1.UITableView 的继承 UITableView : UIScrollView
2.两种样式:1.UITableViewStylePlain 不需要分组显示 如同通讯录
2.UITableViewStyleGrouped 分组模式 如同微信设置
3.UITableView 需要设置两个代理 数据源 代理方法
数据源:UITableViewDataSource 作用:可以规定cell显示多少数据,显示什么数据 cell显示数据全靠这个。
代理方法:UITableViewDelegate 作用:判断cell是否被点击
4.数据源方法有哪些?
1.必选 cell有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
2.cell的显示内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
3.可选 cell有多少组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
4.每一组的组标题 和组尾描述
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
5.cell右侧的索引
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView; //组的索引
6.
UITableView必须知道的属性
1.NSIndexPath,该类拥有两个属性section和row
NSIndexPath:用来标识当前cell的在tableView中的位置
section:标识当前cell处于第几个section中
row : 代表在该section中的第几行。
2.常见属性
rowHeight :统一设置行高
separatorStyle :分割线样式
separatorColor :分割线颜色
sectionHeaderHeight
sectionFooterHeight
tableHeaderView :分组头 一般方法广告
tableFooterView :分组尾: 加载更多
cell自带的属性
imageView :自带左侧图片
textLabel :左侧上面文字
detailTextLabel : 左侧描述文字
contentView :自带的view 防止重用
backgroundView : cell的背景view
selectedBackgroundView :选中时的背景
selectionStyle :样式
accessoryType : 右侧样式 箭头
accessoryView : 右侧可以放view