TableView那点事

来源:互联网 发布:巨峰科技有限公司软件 编辑:程序博客网 时间:2024/06/07 17:27

强烈推荐StackOverflow,所有的问题都是在那找到的答案。

问题1:UITableViewStyleGroup如何让Header、Footer高度为0?

// 我们都知道,仅仅在代理里面写一个返回0是不行的,系统会返回一个默认高度的HeaderView;- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{    DLog(@"子类需要重写 height for Header 方法!");    return CGFLOAT_MIN;}

So…是不是还需要在viewForHeaderInSection里面做文章呢?对的,要这么写:

// 高度为0的时候return nil 就会让高度为0了。 (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{    if ([self tableView:tableView heightForHeaderInSection:section]==0.0) {        return nil;    }else{        UIView *aView = [[UIView alloc] init];        return aView;        }    }}

问题2:scrollViewDidEndScrollingAnimationscrollViewDidEndDecelerating的区别

2.1scrollViewDidEndScrollingAnimation:
这货是系统的scroll动画:(如:
setContentOffset,
reloadData,
UITableViewScrollPositionTop

)
这些才会触发。特别声明:如果你在这些动画的外层使用了隐式动画如:[UIView animateWithDuration: animations:
是不会触发该代理的,因为隐式动画不会去调用scrollView的setContentOffset方法,而是走的setFrame、translation等方法。

2.2scrollViewDidEndDecelerating
这货是你手动滑动一下scrollView而且手要离开屏幕让scrollview自己滚动,在scrollView减速停止的时候触发。
假如你的手一直在scrollView上面未曾离开,手离开的时候scrollView没有运动迹象,那是不会触发该代理的。

问题3:如何更改(void)scrollToRowAtIndexPath: atScrollPosition: animated:的动画时间?
相信看过问题2的朋友已经直到了答案。
对,就是用隐式动画:

[UIView animateWithDuration:0.5 animations:^{            [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];        }];

问题4:自定义cell xib文件报如下错误:

*** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES.’

那请你一定要确保你xib文件中的所有控件都没有设置Class。
我的xib文件中的一个view
被我不小心错误的设置了一个错的Class
如图,我就是不小心给我的一个view控件设置了Class,还TM设错了。。。(宝宝想脱单了可能..)
然后就各种崩…
只要把不该有class的控件去掉class关联就好了。

就BB这么多,毕竟中秋小假期,不能光写博客,还得学习别的东东~

0 0
原创粉丝点击