0

We are placing a temporary label over our UITableViewController view when we need to show a status message. The view goes directly beneath the UINavigationBar. This works well but the statusView scrolls with the table and will disappear as the table scrolls up. How can you fix the statusView position even as the table scrolls?

Update:

What almost works as inspired by another question is to use the TableViewDelegate method to fix the statusView position:

override func scrollViewDidScroll(_ scrollView: UIScrollView) {
    var newFrame = statusView.frame
    newFrame.origin.x = 0
    newFrame.origin.y = self.tableView.contentOffset.y + self.navigationController!.navigationBar.bounds.height 
    statusView.frame = newFrame
}

It places our statusView bar in a fixed position but it's partially underneath the navigation bar. Seems like we just need to tweak the newFrame.origin.y logic....

Update 2:

Per https://stackoverflow.com/a/40202931/47281 just needed to include the status bar:

    newFrame.origin.y = self.tableView.contentOffset.y + self.navigationController!.navigationBar.frame.size.height + UIApplication.shared.statusBarFrame.height 
Community
  • 1
  • 1
Marcus Leon
  • 55,199
  • 118
  • 297
  • 429
  • Is this status view required in particular table cell? If so, why can't you add it to the cell's view instead? Can you share a screenshot perhaps and more code? – Gurtej Singh Mar 31 '17 at 04:07

2 Answers2

0

You can try using a ViewController subclass and add a UITableView to it instead of subclassing UITableViewController.

0

Per updates above solution was inspired by another question - we used the TableViewDelegate scrollViewDidScroll to fix the position:

override func scrollViewDidScroll(_ scrollView: UIScrollView) {
    var newFrame = statusView.frame
    newFrame.origin.x = 0
    newFrame.origin.y = self.tableView.contentOffset.y + self.navigationController!.navigationBar.bounds.height 
    statusView.frame = newFrame
}
Community
  • 1
  • 1
Marcus Leon
  • 55,199
  • 118
  • 297
  • 429