简体   繁体   中英

UITableView don't scroll when it's only composed of section header

I've got an UITableView which contained sections, each with a header view. When you click on a header, the section is expending (so the numbers of rows in the section goes from 0 to X at this moment and rows are inserted with animation)

The problem is that when you don't have any section expended, the TableView won't scroll when you try to go to the bottom for the exemple (when you only have the section headers displayed and 0 row anywhere)

I suspect it's because there is no row at all (because as soon as one section is expended, the TableView is scrolling normally) but I can't find any solutions.

Any idea ?

I would put this in a simple comment but I do not have the reputation to do so. Do the sum of the header views all equate to a height larger than the view that they are in? Additionally, check to make sure you do not have the UITableView does not have the scrolling disabled. If you are unsure, override it with the following code in your ViewDidLoad() method in your UITableView file:

    tableView.scrollEnabled = true

Hope this can help, comment if this does not work and I will try to help you fix it.

If you're using a custom view, an xib file, for your tableView, make sure that the "view" in your xib file is a 'uiview class', not 'uitableviewcell'.

Doesn't matter what custom you use for the view, but the view itself must be a 'uiview'. Delete whatever view you have in your xib, and drag a uiview from object library in xcode and setup from there, your custom class can still be usable by the 'uiview'

may be this will help you

in your viewDidload method

 TableView.alwaysBounceVertical =YES; // it is your choice that you want it vertical or horizontal .
 TableView.directionalLockEnabled = YES;

i used it in my project when my data is smaller for my view but it still my page scrolled.

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