您的位置:首页 > 其它

问题总结1--有关tableView的conntentInset

2016-12-30 17:33 204 查看
1、tableView的contentSize不能改变,是根据tableview的头和脚还有cell的数量和高度,然后通过代理方法实现的,要想手动改变,添加可滑动区域,需要改变tableView的contentInset,具体用法是参照(http://www.xuebuyuan.com/693438.html)中的,为了方便自己使用,在此处复制原文内容:

 程序里UITableView拉到底部,最后一个cell被一个自定义的控件挡住了,只显示了一半,因为UITableView是继承于UIScrollView的,开始想把tablview的contentsize的高度设置大一点点,这样cell应该就显示全了吧,于是照做了,结果木有效果,问题仍然一样,网上查了一下,原来tabelview的contentsize是由它的下列方法共同实现的:
- (NSInteger)numberOfSections;
- (NSInteger)numberOfRowsInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

- (NSInteger)numberOfSections;
- (NSInteger)numberOfRowsInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

它会自动计算所有的高度和来做为它的contentsize的height。

怪不得我设置了,没有用,原来是被自动计算的值结覆盖了,好吧,既然你自动计算了,我就不动你了,设置contentInset吧,在底部多增加一点点空间:

UIEdgeInsets insets = UIEdgeInsetsMake(0,
0, self.navigationController.navigationBar.frame.size.height+faceBoardView.frame.size.height,

0);

tableView.contentInset = insets;

OK,显示完全了。

有关contentSize、contentInset和contentOffset三者的区别,下面贴几张斯坦福大学讲义里的图片,应该一目了然了:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: