UITableView contentInset更改

时间:2016-11-04 13:58:59

标签: ios uitableview

我在方法- (void)viewDidLoad中设置了tableView的contentInset,属性为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

2 个答案:

答案 0 :(得分:4)

您需要在viewDidAppear或viewDidLayoutSubviews方法中更改内容插入内容。

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.tableView.contentInset = UIEdgeInsetsMake(200, 0, 200, 0);
}

答案 1 :(得分:3)

viewDidLoad方法中添加此内容。

self.automaticallyAdjustsScrollViewInsets = NO;
相关问题