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

Grouped table view's footer height #44

Closed
davidevincenzi opened this issue Oct 10, 2016 · 7 comments
Closed

Grouped table view's footer height #44

davidevincenzi opened this issue Oct 10, 2016 · 7 comments
Assignees

Comments

@davidevincenzi
Copy link

Hello,

how can I set the footer height of a normal grouped table view? Since I can't use the table's delegate methods anymore and I don't want to set a view for a model, I cannot find a way to do it otherwise.

Thank you

@DenTelezhkin
Copy link
Owner

Hey, I don't really remember specifics of grouped table view footers, however you can use UITableView delegate methods to change height. Just extend your view controller(or whatever you use as UITableViewDelegate), and those methods will be called:

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

Alternatively, you can also use new events system in DTTableViewManager 5:

manager.heightForFooter(withItem: String.self) { _ in 
    return 20
}

As you can see, i also used simple String instead of model, so that UITableView used tableView(_:titleForFooterInSection:) method instead of tableView(_:viewForFooterInSection:) method.

Hope this helps.

@DenTelezhkin
Copy link
Owner

Oh wow, there's actually a bug on master, where delegate methods for headers and footers are not called. I pushed a fix in ec810e7, can you try and tell me if it works for you?

@davidevincenzi
Copy link
Author

davidevincenzi commented Oct 13, 2016

Hmm, I cannot make it work... I uploaded a sample project here if you want to take a look: https://github.com/augmentedworks/GroupedTest
Neither the table view delegate nor the heightForFooter methods are called.

The DTTableViewManager goes inside this if (line 925):

if configuration.sectionFooterStyle == .title

Therefore it doesn't even reach the last return that you modified in the last commit.

I think that if there's a delegate in the view controller, that should be checked first.
So I would make this:

(delegate as? UITableViewDelegate)?.tableView?(tableView, heightForFooterInSection: section)

as the first check. If there's an override in the view controller, we should just use it.

@DenTelezhkin
Copy link
Owner

DenTelezhkin commented Oct 13, 2016

@augmentedworks Thanks for providing example project.

You need to set a model for section footer for this to work. Modify you example code to following:

manager.memoryStorage.addItem("Woman", toSection: 1)

// Add this line
manager.memoryStorage.setSectionFooterModels([""])

manager.heightForFooter(withItem: String.self) { (model, section) -> CGFloat in
   return 20
}

This way event is getting called, and if you comment event code, delegate will get called as well.

@DenTelezhkin
Copy link
Owner

Oh wow, i misunderstood this for second time. It works for event, but does not work if you want to use UITableViewDelegate methods.
We need to indeed call the delegate there, i'll prepare a fix for this.

@DenTelezhkin
Copy link
Owner

I pushed a fix, UITableViewDelegate is quieried immediately after events, and before we run a custom logic, that varies based on fact that storage may or may not have a model. So now both events for model, and even old plain delegate should work.

Please let me know if i'm being wrong for the third time =) Big thanks for bringing this up, great to fix such stuff around beta period, not in final release. 🍻

@davidevincenzi
Copy link
Author

It works great now!
Thanks a lot for your support and for improving this wonderful library! 🍻

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

No branches or pull requests

2 participants