iOS Developer首页投稿(暂停使用,暂停投稿)iOS收藏

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

2016-07-22  本文已影响412人  Jabber_YQ

在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
上一篇 下一篇

猜你喜欢

热点阅读