Skip to content

Autoresize list of suggestions #5

Open

Description

@VivienGiraud

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.

Activity

  1. mats-claassen commented on Oct 27, 2016

    @mats-claassen
    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.

  2. VivienGiraud commented on Oct 27, 2016

    @VivienGiraud
    Author

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

  3. VivienGiraud commented on Oct 27, 2016

    @VivienGiraud
    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))

  4. mats-claassen commented on Oct 28, 2016

    @mats-claassen
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions