iOS 15 UITableView 分组高度显示异常处理方案

在 iOS15 中UITableView新增了属性有:

/// Determines if the table view allows its cells to become focused.
/// When tableView:canFocusRowAtIndexPath: is implemented, its return value takes precedence over this method.
/// Defaults to a system derived value based on platform and other properties of the table view.
@property (nonatomic, getter=isPrefetchingEnabled) BOOL prefetchingEnabled
/// The height for filler rows added below the last row when there aren't enough rows to fill a plain style table view.
/// Set 0 to disable filler rows entirely, use `UITableViewAutomaticDimension` for the default height.
@property (nonatomic) CGFloat fillerRowHeight
/// Padding above each section header. The default value is `UITableViewAutomaticDimension`.
@property (nonatomic) CGFloat sectionHeaderTopPadding
/// Determines if the table view allows its cells to become focused.
/// When tableView:canFocusRowAtIndexPath: is implemented, its return value takes precedence over this method.
/// Defaults to a system derived value based on platform and other properties of the table view.
@property (nonatomic) BOOL allowsFocus
/// Determines if the table view allows its cells to become focused while editing.
/// When tableView:canFocusRowAtIndexPath: is implemented, its return value takes precedence over this method.
/// Defaults to a system derived value based on platform and other properties of the table view.
@property (nonatomic) BOOL allowsFocusDuringEditing

方法:

// Reconfigures any existing cells for the rows. Reconfiguring is more efficient than reloading a row, as it does not replace the
// existing cell with a new cell. Prefer reconfiguring over reloading unless you actually need an entirely new cell for the row.
- (void)reconfigureRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths 
/// Determines if the row at the specified index path should also become selected when focus moves to it.
/// If the table view's global selectionFollowsFocus is enabled but this delegate returns NO, focus will still move to the cell upon selection, but the cell will no longer become selected when focus moves to it.
- (BOOL)tableView:(UITableView *)tableView selectionFollowsFocusForRowAtIndexPath:(NSIndexPath *)indexPath

其中属性值sectionHeaderTopPadding, 设sectionHeaderTopPadding为 0即可。

  • 部分页面设置
if (@available(iOS 15.0, *)) {
    _tableView.sectionHeaderTopPadding = 0;
}
  • 全局设置
if (@available(iOS 15.0, *)) {
    [UITableView appearance].sectionHeaderTopPadding = 0;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容