0

I have UIViewController that has a Navigation Bar. At run time, I am adding (on viewDidLoad) a UITable. The problem I have is an inconsistent behaviour of the UITableView y-position.

In viewDidLoad I set the UITableView frame to:

tableView = UITableView(frame: self.view.frame)

then:

self.view.addSubview(tableView)

The problem: on the odd occasion, and only on iphone 4s, the table is added underneath the NavigationBar resulting in the first row not being visible to the user (put another way: y-pos = 0).

If I try to set the y-pos to status bar height + nav bar height the table is always positioned too low (i.e. at the wrong y-pos)

Am I doing something wrong or have I stumbled upon random quirk of ios 9.2 & swift 2?

zevij
  • 2,416
  • 1
  • 23
  • 32

1 Answers1

0

Hope this will help

Try following in controller's viewDidLoad Method :

self.automaticallyAdjustsScrollViewInsets = NO;

or You can disable it from Attribute Inspector as given in below image.

enter image description here

technerd
  • 14,144
  • 10
  • 61
  • 92
  • Hmmm...when I do that then on all phones the first row of the table is masked/hidden by the nav bar. Looking at this answer, http://stackoverflow.com/a/19129292/1176660, my case is the second one described (the UITableView is the first subview) so in theory, my original settings should work. However, as stated, on iphone 4s + ios 9.2 it sometimes fail (I have two devices - on one it works and on the other it does not :( ) – zevij Dec 23 '15 at 18:44