问题总结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三者的区别,下面贴几张斯坦福大学讲义里的图片,应该一目了然了:
程序里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三者的区别,下面贴几张斯坦福大学讲义里的图片,应该一目了然了:
相关文章推荐
- ios tableview 小问题总结
- 使用sqlite3 有关tableview删除cell的问题
- IOS学习日志---1:TableView下拉刷新以及各种失败问题总结
- ios之基础tableview的问题总结
- HY项目中问题总结(tableview 的细节处理以及基类的使用)
- 有关使用tableview的问题
- iOS 11中APP中tableView内容下移20pt或下移64pt的问题适配的一个总结
- 思考问题的本质--有关提炼总结的思维习惯
- 有关网页抓取问题的一些经验总结
- 工作中与处理器有关的问题总结
- 有关display:block、display:table-cell在IE、谷歌的兼容性问题
- 向上滑动tableview 程序crash问题
- 有关View的frame、Bounds、contentMode、ClipstoBounds的问题
- 有关视图状态(ViewState)的一些问题
- [开发总结]WebView使用中遇到的一些问题&解决
- 如何解决关于TableView里面cell随机显示的问题
- 转 [开发总结]WebView使用中遇到的一些问题&解决
- 有关datalist绑定table问题
- 如何解决关于TableView里面cell随机显示的问题
- 有关socket通信包大小的问题总结(UDP传输模式)