我对这个topLayoutGuide方法有一些奇怪的问题,我必须在setAutomaticallyAdjustsScrollViewInsets:不起作用的情况下使用它.为了缩小问题的原因,我创建了以下最小的示例,它只是为测试设置了一个基本的表视图:
在ViewController.m的实现中粘贴以下代码:
@implementation ViewController
- (void)loadView
{
[self setTableView:[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self setAutomaticallyAdjustsScrollViewInsets:NO]; // [*]
}
- (void)viewDidLayoutSubviews
{
UITableView *tableView = [self tableView];
UIEdgeInsets insets = [tableView contentInset];
// insets.top = [[self topLayoutGuide] length]; // [1]
// insets.top = 100; // [2]
[tableView setContentInset:insets];
[tableView setScrollIndicatorInsets:insets];
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 100;
}
- (UITableViewCell *)tableView:(UITableView …Run Code Online (Sandbox Code Playgroud)