第一個section上邊多余間距處理
// 隱藏UITableViewStyleGrouped上邊多余的間隔
_tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
每個section下邊多余間距處理
// 隱藏UITableViewStyleGrouped下邊多余的間隔
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
- 備注:若傳入的 height == 0,則 height 被設置成默認值
- 若 height 小于屏幕半像素對應的高度,則不會被渲染,所以這里返回CGFLOAT_MIN,其實返回0.01也是可以的
補充:代碼順序的不同導致第一個section上邊出現多余間距
- 在設置代理
前
設置tableFooterView,上邊會出現
多余間距
tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
tableView.tableFooterView = [UIView new];
tableView.delegate = self;
tableView.dataSource = self;
- 在設置代理
后
設置tableFooterView,上邊不會出現
多余間距
tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
tableView.delegate = self;
tableView.dataSource = self;
tableView.tableFooterView = [UIView new];
- 可以通過
第一個section上邊多余間距處理
的辦法來解決因代碼順序導致的上述問題,所以這里建議要解決第一個section上邊多余間距
還是通過文章開頭所說的解決辦法更好
參考文章
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。