Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't remove top extra space for grouped tableview #84

Closed
SergeMaslyakov opened this issue Jun 14, 2018 · 8 comments
Closed

Can't remove top extra space for grouped tableview #84

SergeMaslyakov opened this issue Jun 14, 2018 · 8 comments

Comments

@SergeMaslyakov
Copy link

Hi.

I have faced for strange behaviour of grouped tableview with TableKit.
I can't remove extra top space for grouped table (I use xibs - iOS 10/11).

I do following:

    func reload(withModels models: [MyModel]) {

        tableDirector.clear()

        let section = TableSection()
        tableDirector += section

        section.headerHeight = CGFloat.leastNormalMagnitude
        section.footerHeight = CGFloat.leastNormalMagnitude

        for item in models {

            section += TableRow<MyTableViewCell>(item: item)
                    .on(.click, handler: { [weak viewOutput] _ in

                    })
        }

        tableDirector.reload()
    }

Also I have tried to make subclass of TableDirector and always return CGFloat.leastNormalMagnitude for all sections. It's didn't work also.

--- But ----
If I implement datasource/delegate manually. It works fine - no any extra space on top.


extension MyTableDataSource: UITableViewDelegate {
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return MyTableViewCell.defaultHeight
    }

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return CGFloat.leastNormalMagnitude
    }

    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return CGFloat.leastNormalMagnitude
    }
}

@maxsokolov
Copy link
Owner

maxsokolov commented Jun 14, 2018

Hey @SergeMaslyakov

I've tried to reproduce the issue in the demo app from the repo. What I've done:

  1. Set group style from table view in a storyboard for main controller. Right after that I can see extra space on top.
  2. Then in MainController.swift added a section and set:
section.headerHeight = CGFloat.leastNormalMagnitude

Extra space disappeared.

Further steps:

  1. Could you provide a demo app with the issue?
  2. Or try to create a section in the following way:
TableSection(headerView: UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNormalMagnitude)), footerView: nil)

@SergeMaslyakov
Copy link
Author

@maxsokolov, thanks for answer. I want to note that I use xib instead storyboards.

Anyway, I have done bit demo.
See this repo demo repo

For GithubClient/src/modules/GistsBrowser/View/GistsBrowserViewController is implemented two datasources. TableKitGistsBrowserTableDataSource uses TableKit and other one BaseGistsBrowserTableDataSource manages table stuff itself.

You can switch them by uncommenting in the GistsBrowserViewController .

@maxsokolov
Copy link
Owner

@SergeMaslyakov alright, thanks for the demo!

I've started investigation. Here is what I've done in TableKitGistsBrowserTableDataSource:

let section = TableSection()
let sectionHeader = UIView(frame: CGRect(x: 0, y: 0, width: 150, height: 300))
sectionHeader.backgroundColor = UIColor.red
section.headerView = sectionHeader
tableDirector += section

//section.headerHeight = CGFloat.leastNormalMagnitude
//section.footerHeight = CGFloat.leastNormalMagnitude

screen shot 2018-06-15 at 00 44 39

Still a gap.. pff.. nice.
And then:

tableView.tableFooterView = nil
tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 150, height: CGFloat.leastNormalMagnitude))

Result:
screen shot 2018-06-15 at 00 46 56

I don't know any better solution for now.

@SergeMaslyakov
Copy link
Author

@maxsokolov

Thanks for help and workaround.
I think it's related to xib's, bcoz this isn't reproduced when I use a storyboard.

@SergeMaslyakov
Copy link
Author

@maxsokolov

Hi again. I have found some interesting thing.

This problem appears when I use lazy var for TableDirector

    private lazy var tableDirector: TableDirector = {
        return TableDirector(tableView: tableView)
    }()

When I declare it as a simple var the problem disappears.

    private var tableDirector: TableDirector

@hastlerr
Copy link

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return CGFloat.leastNormalMagnitude
}

@kishanbarmawala
Copy link

@SergeMaslyakov alright, thanks for the demo!

I've started investigation. Here is what I've done in TableKitGistsBrowserTableDataSource:

let section = TableSection()
let sectionHeader = UIView(frame: CGRect(x: 0, y: 0, width: 150, height: 300))
sectionHeader.backgroundColor = UIColor.red
section.headerView = sectionHeader
tableDirector += section

//section.headerHeight = CGFloat.leastNormalMagnitude
//section.footerHeight = CGFloat.leastNormalMagnitude
screen shot 2018-06-15 at 00 44 39

Still a gap.. pff.. nice.
And then:

tableView.tableFooterView = nil
tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 150, height: CGFloat.leastNormalMagnitude))

Result:
screen shot 2018-06-15 at 00 46 56

I don't know any better solution for now.

It's also working for me... Thanks... you saved my day!

@AKGupta31
Copy link

If you are using header view also then you just need to do the following..

func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}

It worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants