验证
验证一下有关于苹果自带表视图分割线不顶头的解决办法
- (void)viewDidLayoutSubviews {
if ([self.tv respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tv setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
if ([self.tv respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tv setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
}
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self.tv respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tv setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
if ([self.tv respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tv setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
}
}
然并卵,理论上说,数据源代理函数返回的行中,都不会生效。(人家西方人就喜欢这种不对称美,无可厚非)
不过既然用到了下面的方法,还是值得说一说的
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
这个方法表视图性能调优的重要方法,可以将cell和数据分离,提高性能。
常用知识点总结:
1、tableview的组头会滞留在顶部,如果不需要滞留在顶部,可以采用UITableView的Group样式,组与组之间默认的间距是35,在返回组头视图高与组尾视图高来控制这个间距,如果设置为0 ,间距仍为35 ,如果想设置为0 可以设置为0.01。
2、在自定义的cell中,很多子控件的初始化是在下面这个方法中进行的
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
return self;
}
在实际布局中,我们可能需要拿到cell的frame进行一下设置,在表视图的代理中,我们知道返回cell之前先要执行返回高度的方法,所以上面这个方法是后执行的,那么是不是在执行这个方法的时候我们已经可以获取到高度呢,其实不然,所有cell在创建的时候返回的高度均为44,在willdisplaycell的方法中,我们才可以拿到精确的cell,所以我们可以将更新cell的工作放在这个方法里,同时还可以在赋值之前利用cell的frame进行布局。