表视图
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
在视图滚动时调用此方法,基于UIView。
contentoffset是UIScrollView的一个属性,表示当前显示视图顶点距离frame的偏移量
contentSize 表示可显示视图的大小,大小超过了frame可以通过滚动来查看,比如frame是(0,0,320,480),contentsize是(320, 1000),那scrollView的范围就是(320, 1000),超出的部分可以通过滚动来查看下面的东西
viewController写TableViewController必须继承UITableViewDataSource, UITableViewDelegate这两个协议,而且必须实现以下俩个方法cell数量和cell的设置
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
cell的数量,需要return返回
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
cell的设置,一般都固定写法- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
cell的高度,需要return返回- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
点击cell 的方法,可以推出下一个视图,可以属性传值- (void)setSelected:(BOOL)selected animated:(BOOL)animated
cell被选中的动画方法图片在cell上的自适应高度公式cell的高度 = cell的宽度 * 图片的高度 / 图片的宽度
setAccessoryType cell的辅助视图
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
判断能不能移动- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
tableView中每一行移动的方法
自定义cell时
UIView初始化完以后会调用- (void)layoutSubviews方法 需要先调用父类layoutSubviews
其实的self.contentView是铺在cellView上的一层,往cell上放东西都放他上面(为了防止铺在cell上东西太多导致调用混乱)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
section区域的数量- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
section的header title的名字,就是每个区域section的名字- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
标题的高度
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
标题的设置,每个Section区域的头
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
侧栏的titles,就像通讯录右边的ABCD。。。