UITableView contentInset 变化

Aar*_*ron 2 uitableview ios

我已经在方法中设置了 tableView 的 contentInset- (void)viewDidLoad并且属性是self.tableView.contentInset = UIEdgeInsetsMake(200, 0, 200, 0);tableView.contentInset 将自动更改为 : 。{64, 0, 0, 0} 为什么会发生这种情况,我该如何解决这个问题?

环境:XCode8.1 iOS10.1

    #import "YAVideoViewController.h"
static NSString * const ID = @"cell";
@interface YAVideoViewController ()

@end

@implementation YAVideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];



    self.view.backgroundColor = [UIColor arcColor];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:ID];

    self.tableView.contentInset = UIEdgeInsetsMake(200, 0, 200, 0);
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 50;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath];

    cell.textLabel.text = [NSString stringWithFormat:@"?%ld?cell",indexPath.row];

    return cell;
}

@end
Run Code Online (Sandbox Code Playgroud)

小智 5

将此添加到您的viewDidLoad方法中。

self.automaticallyAdjustsScrollViewInsets = NO;
Run Code Online (Sandbox Code Playgroud)