Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Misplaced or hidden UITableView Section Header while switching from one datasource to another and realoding the UITableView

I am making a profile view on iOS which has three tabs like twitter app. I am using one table view and when user taps on these tabs I am reloading it from other data sources. But I want to keep the section header to be on the top independent of these data source models.Is there is any way to achieve it?

Sometimes when user taps on button of section header to switch the table view data source and reload again, but section header view either gets hide or misplaced from its original top position, Its a weird kind of bug, Any hint what's going on here?

Edit : - One important thing is I am having pull to refresh also here.

enter image description here

enter image description here

like image 232
kidsid49 Avatar asked Nov 29 '15 23:11

kidsid49


4 Answers

you can make a unique view to store your section Header,then put the view head of the controller. That can achieve your goal.

like image 185
pAn zHou Avatar answered Nov 13 '22 06:11

pAn zHou


But I want to keep the section header to be on the top independent of these data source models.Is there is any way to achieve it?

If I understand you correctly you maybe better served by using the table header view property. Why? because would give you the independence you want from the data source reloading, but maintain your ability to fire the data source reload from your three controls.

You could also follow @WolfLink's advise and put a view above your table view to achieve the same thing.

This is course dependent of how you use your table sections. See this SO question for adding a header view to your table view.


EDIT

If you want the current section view to always be at the top of it's super view then you should re-arrange you view controller's view hierarchy so that your section header view is implemented out side of the table view.

ViewController's subviews

        ---> view containing your three buttons(Current section header view)
        ---> table view
        ---> toolbar

This way even when the user scrolls the table view, the three button view will still stay at the top of the screen.


like image 37
Peter Hornsby Avatar answered Nov 13 '22 06:11

Peter Hornsby


I think it is a scrolling issue, i have had similar issue before, UITableView is built on top of UIScrollView, and scroll view has setContentOffset method, call this after reload and set offset to (0,0)

like image 3
Karthik Avatar answered Nov 13 '22 08:11

Karthik


You can use this library: https://github.com/toandk/DTTableView

In the example, there is a table view DTParallaxTableView initiated with a header view: DTParallaxHeaderView and a UIVIew (which can be a tab bar like in this sample).

You can disable the parallax effect if not useful and use it to launch the pull to refresh.

Or search here and find the one that match with your use case! https://www.cocoacontrols.com/search?q=pull

like image 3
Alban Avatar answered Nov 13 '22 07:11

Alban