Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView content offset -64pt issue

I am debugging table view and in my -viewDidLoad method I have:

<UITableView: 0x7b394600; frame = (0 0; 1024 768); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7983d2f0>; layer = <CALayer: 0x79836ca0>; contentOffset: {0, 0}>

but when I check the frame and content offset in -viewDidAppear method:

<UITableView: 0x7ab79c00; frame = (0 0; 1024 768); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7998f700>; layer = <CALayer: 0x7998f560>; contentOffset: {0, -64}>

I don't know how table get -64 for its offset.

There is just sequence of methods view did load and then view did appear but content offset magically changed for me.

What can be a reason?

This is my viewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];

    _theTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];

    _theTableView.dataSource = self;
    _theTableView.delegate = self;

    [self.view addSubview:_theTableView];

    _theTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

    self.title = @"File Manager";
}

I have navigation bar, but weird that I see my table as it should be without shifting. So looks perfect I see top cell and when I scroll to the bottom I see last cell. Even indicator says to me that content offset is 0. If I force set content offset {0, 0} then seems like first cell goes under navigation bar and vertical indicator starts not from the top but with some padding about 64 pt, but it's strange.

I suppose this is because of status bar and navigation bar. But if hardcoded create my offset and frame, it does not help me. Seems like system does it form me automatically =)

like image 830
Matrosov Oleksandr Avatar asked Apr 01 '15 14:04

Matrosov Oleksandr


1 Answers

This is the default behaviour, look into automaticallyAdjustsScrollViewInsets:

Default value is YES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set to NO if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.

…and other related things in iOS 7 UI Transition Guide.

like image 187
Nikita Kukushkin Avatar answered Sep 24 '22 10:09

Nikita Kukushkin