Swift: Fixed header in a TableViewController

0

My problem is this: my application has a screen that uses the UITableViewController layout. I created a header (View) for this screen, however, the header does not stay fixed at the top of the screen. That is, when I drag the screen up / down, the header also moves up / down. My question is is there any way to keep a subview fixed at the top of the screen, and is this subview in UITableViewController?

ps: I tried this solution but it did not work.

override func scrollViewDidScroll (scrollView: UIScrollView)  {
    var fixedFrame: CGRect = self.uiTopView.frame;
    fixedFrame.origin.y = scrollView.contentOffset.y;
    self.uiTopView.frame = fixedFrame;
}
    
asked by anonymous 08.09.2016 / 17:35

2 answers

1

Use a UIViewController instead of a UITableViewController.

Create your screen with your view you want to leave fixed and your tableview just below.

In your UIViewController you also inherit a UITableViewDelegate and a UITableViewDataSource. Place your tableview via IBOutlet in your ViewController and have your tableview get the dataSource and Delegate of your class, for example:

self.tableView.dataSource = self self.tableView.delegate = self

That way the "Scrollable" area will be just your tableView and not your entire view.

I hope I have helped in some way;)

    
16.09.2016 / 16:40
-1

Breno, try this:

override func scrollViewDidScroll (scrollView: UIScrollView)  {
    self.uiTopView.frame.origin.y = max(0.0, self.scrollView.contentOffset.y)
}

Do not forget to add the delegate in scrollView

    
20.09.2016 / 21:10