0

I have two UITableView's instances. When I add them as subviews to the root view of the UIViewController, which is in a UINavigationController, I got one of them was automatically added contentOffset with y is -64, because of the new property automaticallyAdjustsScrollViewInsets, but another one is 0. Only the first one will be adjusted.

I have do some research from Apple's Documents and the Internet. Still cannot find any clue.

Here is the code I adding the table views.

- (void)viewDidLoad
{
    [super viewDidLoad];

    // the table views are init in their getter methods
    // both frames are equal to root view of this view controller

    [self.view addSubview:self.firstTableView];
    [self.view addSubview:self.secondTableView]; // this one will not have contentOffset
}

After the addSubview, 'cause I want both of them have contentOffset. But even I have try to set contentOffset to secondTableView manually, somehow it was change back to 0 after the view controller was shown, the break point is in viewDidAppear:, on the screen.

Miscs: Xcode 5.0.2, iOS 7 SDK, ARC, neither Storyboards nor xibs.

I will be grateful if any one could help me with this.

vc7
  • 23
  • 1
  • 7

1 Answers1

0

This problem would be easier to solve if you were using storyboards. It sounds like autolayout is automatically making the contentOffset adjustment for you, despite never explicitly asking it to. See this answer for a very similar (or exactly the same?) issue with one UITableView seemingly being different from another identical UITableView. Xcode may be assuming that one of your instantiated UITableView objects is the topmost UIView.

Community
  • 1
  • 1
Mike S
  • 11,329
  • 6
  • 41
  • 76
  • The question is very similar to mine. But the `contentOffset` padding was made by `automaticallyAdjustsScrollViewInsets` property setting, rather than autolayout. So Xcode will only take care of the first UIScrollView-like instance for me? – vc7 Feb 13 '14 at 06:53