【问题标题】:UITableView adjust content inset not unitl 1st scrollUITableView 调整 contentinset 直到第一次滚动
【发布时间】:2018-08-10 22:42:55
【问题描述】:

在尝试使用 searchBar 创建 tableview 时,我遇到了 tableView 自动调整 contentInset 的问题,但直到第一次滚动。在另一个 tableView 上,没有 searchBar 的地方不存在问题。 searchController 的设置几乎是从 Apples TableSearchWithUISearchController 示例中删除的。 所以我的代码被 viewDidLoad 中的 TableViewController 调用:

resultsController = [[ResultConstantTVController alloc] init];
searchController = [[BaseSearchController alloc] initWithSearchResultsController:resultsController];
searchController.searchResultsUpdater = self;
searchController.delegate = self;

self.navigationItem.searchController = searchController;
self.navigationItem.hidesSearchBarWhenScrolling = NO;
[self.searchBar setBarStyle:UIBarStyleBlackTranslucent];
[self.searchBar setKeyboardAppearance:UIKeyboardAppearanceDark];
[self.searchBar setAutocapitalizationType:UITextAutocapitalizationTypeNone];
self.definesPresentationContext = YES;
self.dimsBackgroundDuringPresentation = NO;

我已经尝试将 tableViews contentInsetAdjustmentBehavior 手动设置为自动,但直到第一次滚动时它仍然不会生效。

在 firstScroll 之前

第一次滚动后

附:我正在使用 Xcode、macOS 和 iOS 的 beta 版本。

更新:

我设法通过调用绕过了这个问题

[self.navigationController.view layoutSubviews];

在 TableViewController 中的 viewDidAppear 中。

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:

    我已经尝试将 tableViews contentInsetAdjustmentBehavior 设置为自动

    没错,但还不够。这类问题通常也可以通过将表视图的alwaysBounceVertical 设置为YES 来解决。您需要在视图控制器生命周期的早期执行此操作。

    【讨论】:

    • 我需要看看“它”是什么。在视图控制器的生命周期中,您可能做得不够早。 ——但这不是批评,我也不是说这个解决方案是确定的;从 iOS 11 开始,您所描述的问题绝对是一个问题。我建议的解决方法是由 Apple 员工提供给我的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-22
    • 1970-01-01
    相关资源
    最近更新 更多