简体   繁体   中英

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.

在此输入图像描述

在此输入图像描述

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

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.


我认为这是一个滚动问题,我之前遇到过类似问题,UITableView建立在UIScrollView之上,滚动视图有setContentOffset方法,重新加载后调用此方法并将偏移量设置为(0,0)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM