Byte Byte - 1 year ago 137
iOS Question

Presenting TableView with header instead of middle section or footer

I have a custom tableView with a header and some sections. I am using tabs to between three viewControllers. ViewController with tableview is my home page of the app. When I first open the app every thing is okay. But if I scroll down my tableView and then move to some other viewController using tab and come back to my Home screen, TableView is presented with the section where I left. I want it to be presented with header(my viewController should be presented from top instead of middle) Here are the screen shots.

This is my home screen

enter image description here

And If I scroll down like below

enter image description here

And move to next screen using below tabBar

enter image description here

This is what i get when I come back to home screen

enter image description here

Should it not be presented same as first time ?

Answer Source

In your first tab's viewControllers, add following code inside viewWillAppear() method.

let scrollPoint = CGPoint(x: 0, y: 0)
self.tableView.setContentOffset(scrollPoint, animated: false)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download