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

Autoresize list of suggestions #5

Open
VivienGiraud opened this issue Oct 27, 2016 · 4 comments
Open

Autoresize list of suggestions #5

VivienGiraud opened this issue Oct 27, 2016 · 4 comments

Comments

@VivienGiraud
Copy link

Hi,

Just change:

tableView?.frame = CGRect(x: 0, y: frame.origin.y + frame.height, width: contentView.frame.width, height: 44*5)

To

tableView?.frame = CGRect(x: 0, y: frame.origin.y + frame.height, width: contentView.frame.width, height: 44 * CGFloat((suggestions?.count)!))

In function showTableView()
A bit quick&dirty but that works.

@mats-claassen
Copy link
Member

Yeah that 5 is not very nice. A possible solution would be to add a new variable to SuggestionRow which defines how many rows will be shown in the suggestion table as maybe suggestions.count is too large.

@VivienGiraud
Copy link
Author

TBH suggestions.count works great, I'm just looking to replace that 44 :)

@VivienGiraud
Copy link
Author

I understand what you meant by "is too large", then you can do the "Quick & Dirty AF" version:

let frame = controller.tableView?.convert(self.frame, to: controller.view) ?? self.frame
tableView?.frame = CGRect(x: 0, y: frame.origin.y + frame.height, width: contentView.frame.width, height: 44 * (((suggestions?.count)! <= 5) ? CGFloat((suggestions?.count)!) : 5))

@mats-claassen
Copy link
Member

Well you are correct in that the 44 should also be parametrizable.
I believe this problem is best fixed if we add two variables with sensible default values instead of using hardcoded 44 and 5. The variable for the amount of rows would be a maximum like so:
height = min(suggestions.count, maxNumberOfRows)

What do you think?

The question that arises then is what if there are no suggestions? Show x empty rows? Showing nothing might not look good.

A possibility would be:
height = max(3, min(suggestions.count, maxNumberOfRows))

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