【发布时间】: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 手动设置为自动,但直到第一次滚动时它仍然不会生效。
附:我正在使用 Xcode、macOS 和 iOS 的 beta 版本。
更新:
我设法通过调用绕过了这个问题
[self.navigationController.view layoutSubviews];
在 TableViewController 中的 viewDidAppear 中。
【问题讨论】:
标签: ios objective-c uitableview