tableView不同样式的留白或者分割线过多

作者: Jabber_YQ | 来源:发表于2016-07-22 15:26 被阅读412次

在tableview的初始化过程中,经常会使用下面方法

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style 

UITableViewStyle有两个样式

typedef NS_ENUM(NSInteger, UITableViewStyle) {
    UITableViewStylePlain,          // regular table view
    UITableViewStyleGrouped         // preferences style table view
};

UITableViewStylePlain

在使用UITableViewStylePlain时会出现行数过多问题
解决方法是用view盖住

    UIView *view =[ [UIView alloc]init];  
  
    view.backgroundColor = [UIColor clearColor];  
  
    [tableView setTableFooterView:view];  
  
    [tableView setTableHeaderView:view]; 

UITableViewStyleGrouped

当使用UITableViewStyleGrouped时候,tableview的顶部会出现留白问题


屏幕快照 2016-07-22 下午3.19.10.png

解决方法是:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1;
}

这样留白就消失了


屏幕快照 2016-07-22 下午3.21.07.png

相关文章

网友评论

    本文标题:tableView不同样式的留白或者分割线过多

    本文链接:https://www.haomeiwen.com/subject/faeijttx.html