ElaWorkshop / TagListView

Simple and highly customizable iOS tag list view, in Swift.
MIT License
2.64k stars 492 forks source link

Extra empty row issue #146

Open hecode opened 7 years ago

hecode commented 7 years ago

iphone 6 simulator screenshot as you can see there is a third row that is empty after the two full rows.

the taglistview is in a view in a custom table cell, and is using the following settings

        tagListView.paddingY = 5
        tagListView.paddingX = 7
        tagListView.tagBackgroundColor = UIColor(red: 225/255, green: 225/255, blue: 225/255, alpha: 1)
        tagListView.textColor = UIColor.lightGray
        tagListView.marginX = 10
        tagListView.marginY = 10

using swift 3 version

Cee commented 7 years ago

So what is your custom table cell's height and width? And how you initialize this TagListView?

hecode commented 7 years ago

screen shot 2017-09-14 at 8 09 39 pm

screen shot 2017-09-14 at 8 02 19 pm

hecode commented 7 years ago

removing the trailing constraint on the taglistview fixes it, but causes the tagslistview to not fill the full width on iPad. (the tagslistview takes the same width as it does on iphone)

Cee commented 6 years ago

You can set priority to your constraint, depening on whether it is an iPad or iPhone.

hecode commented 6 years ago

sorry again, it seemed that removing the constraint fixes it, but while trying other data and trying the uidebugger it actually just crams the tags in a width smaller than the cell width. so unfortunately still have the same problem.

annjawn commented 6 years ago

I am facing the exact same issue. I have a UITableViewCell nib with TagListView in it which is inside a Stack view and the stack view is pinned 8 pts to Top, Bottom, Leading and Trailing of the tableviewcell's content view. No matter what I do, there seems to be this extra space at the bottom of the TagListView which I am unable to get rid of. By the way my Tableview uses tableView.rowHeight = UITableViewAutomaticDimension so it will expand/shrink based on it's content, so i don't believe it's a table view cell height issue. I have other Custom tableview cells with variable heights and they all operate correctly except for this one which is slightly taller.

hegedus90 commented 6 years ago

Take a look at the implementation of rearrangeViews. The number of rows is determined using the cell's actual frame. If you are using UITableViewAutomaticDimension, chances are rearrangeViews is called before the cell's proper width is set (and it uses the width which is set in the xib file).

Something like this can fix your issue:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    ...
    let cell = tableView.dequeueReusableCell(withIdentifier: "TagsCell", for: indexPath) as! TagsCell
    cell.contentView.frame.size.width = tableView.frame.width
    cell.contentView.layoutSubviews()
    tagListView.addTags(tags)
    ...
}
annjawn commented 6 years ago

@hegedus90 I've found a rather hackish way of solving the problem, but I will give this one a try. It also looks like if used in a tableview cell then this delegate is necessary otherwise the list tags just keeps on adding everytime the cell is dequeued and queued back again.

override func prepareForReuse() {
        tagListView.removeAllTags()
}