Here is a tableView with 5 cells and one section. there is a blue gap when pulling the tableView to refresh.
here is the code:
- (UITableView *)salesRankTableView{
if(!_salesRankTableView){
_salesRankTableView = [[UITableView alloc] initWithFrame: CGRectMake(8, 183, KScreenWidth - 16, KScreenHeight-183-64) style: UITableViewStyleGrouped];
[_salesRankTableView registerNib: [UINib nibWithNibName: NSStringFromClass(SalesRankTableViewCell.class) bundle:nil] forCellReuseIdentifier: kSalesRankTableViewCell];
_salesRankTableView.layer.contents = (__bridge id _Nullable)([UIImage imageNamed: @"blue"].CGImage);
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget: self refreshingAction: @selector(rankRefresh)];
header.layer.contents = (__bridge id _Nullable)([UIImage imageNamed: @"white"].CGImage);
_salesRankTableView.mj_header = header;
}
return _salesRankTableView;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 56;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
return [UIView new];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
return [UIView new];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return CGFLOAT_MIN;
}
In order to get rid of the blue gap in the front of the tableView. I changed the tableView's backgroundColor. And met an other question.
The empty space's backgroundColor of the tableView matters. How to set it different?
Here is the code:
- (UITableView *)salesRankTableView{
if(!_salesRankTableView){
_salesRankTableView = [[UITableView alloc] initWithFrame: CGRectMake(8, 183, KScreenWidth - 16, KScreenHeight-183-64) style: UITableViewStyleGrouped];
[_salesRankTableView registerNib: [UINib nibWithNibName: NSStringFromClass(SalesRankTableViewCell.class) bundle:nil] forCellReuseIdentifier: kSalesRankTableViewCell];
_salesRankTableView.layer.contents = (__bridge id _Nullable)([UIImage imageNamed: @"white"].CGImage);
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget: self refreshingAction: @selector(rankRefresh)];
header.layer.contents = (__bridge id _Nullable)([UIImage imageNamed: @"white"].CGImage);
_salesRankTableView.mj_header = header;
}
return _salesRankTableView;
}
I used to insert a white view behind the tableView with the prior code.
It is a little wield , How to do it better?