ElaWorkshop / TagListView

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

Height issue with TableView Cell #191

Open ErAshu opened 6 years ago

ErAshu commented 6 years ago

TagView height is not working perfect with tableView Cell.

Its clipping from bottom.

Cee commented 6 years ago

How do you layout TagView in a tableview cell?

ErAshu commented 6 years ago

See the attached Screenshot.

screen shot 2018-07-20 at 11 49 02 am screen shot 2018-07-20 at 11 48 35 am
Cee commented 6 years ago

What's the code in tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat method?

pvn-anh-pham commented 6 years ago

I also get this issue. In my case, when I change height of tableview cell (static cell), the tagview doesn't.

ErAshu commented 6 years ago

UITableViewAutomaticDimension

tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat

priyankakanojia36 commented 6 years ago

I am having the same issue. kindly help me. why this section is closed I read here but I dint find the solution for it. revert asap.

AalokParikh commented 5 years ago

I also get this issue. In my case, when I change the height of the TableView cell (static cell), the tag view doesn't.

I got the same issue. Would you able to resolve it?

ThoseGuysInTown commented 5 years ago

Any update on this?

This is what the issue looks like for me: image The cell is set to UITableView.automaticDimension but the view doesn't expand enough. The last 3 rows are cut off from any taps.

pquy1008 commented 5 years ago

Same problem. My UITableViewCell doesn't expand enough.

MarjanBasiri commented 5 years ago

What's the code in tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat method?

Any solution??!!

lvyongtao commented 5 years ago

add notificaiton to reload superview frame. it is not best way, but this way can deal it.

EmreSURK commented 5 years ago

Same here. Conflict happens when there are other views in the same cell and have multiple rows of tags.

ultimatevegance commented 5 years ago

I also have the same problem ,I am thinking that the TagListView content layout is finished before table view reload completed so that the cell which contains the TaglistView did not updated it's content layout. what I do is just reloading the tableview layout after reloadData() :


 tableView.reloadData()
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {[weak self] in
            self?.tableView.beginUpdates()
            self?.tableView.endUpdates()
        }

and the problem solved: may this help

ghost commented 5 years ago

I also have the same problem ,I am thinking that the TagListView content layout is finished before table view reload completed so that the cell which contains the TaglistView did not updated it's content layout. what I do is just reloading the tableview layout after reloadData() :

 tableView.reloadData()
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {[weak self] in
            self?.tableView.beginUpdates()
            self?.tableView.endUpdates()
        }

and the problem solved: may this help

Awesome. It worked for me thanks alot

Pirokar commented 4 years ago

Also for me the solution is to set margins and paddings programmatically, not from interface builder:

tagListView.paddingX = 7
tagListView.paddingY = 7
tagListView.marginX = 7
tagListView.marginY = 7 
Udaykumarv commented 4 years ago

by using tagListView.subviews.count we can get the height.

height = (tagListView.subviews.count * 32) + topMargin + bottomMargin

this will fix height issue

specialfor commented 3 years ago

I had similar issue and resolve it thanks to reloadData call inside viewDidAppear one. The solution was found here: https://github.com/zekunyan/TTGTagCollectionView#fix

SSnowCat commented 3 years ago

hey guys, i have the proplem, i'm try reload the tableview layout,but not working,please help me

anelad commented 3 years ago

I'm using TagListView in a table view with static cells. I calculate my TagListView's height like this:

import Foundation
import TagListView

extension TagListView {

    var height: CGFloat {
        // row count. If tagView doesn't have an item it will be 0
        let count = CGFloat(self.subviews.count)
        // subview (aka row) height. If no row exists 'first' item will be nil, so we set 0.
        let height = self.subviews.first?.frame.height ?? 0
        // margin
        let margin = self.marginY

        // calculate total height.
        // subview count times height + subview count - 1 times margin
        // if count is 0 we don't want to make the view minus margin height
        return CGFloat((count * height) + (count == 0 ? count : count - 1)) * margin)
    }

}

This will give you the exact height of the view.

Now you can set the cell height:

if you are using static cells like me:

@IBOutlet weak var myCell: UITableViewCell

func someFunct() {
    // do stuff
    myCell.frame.size.height = tagList.height
}

if you are using dynamic cells :

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.row == theRowYouWant {
        return tagList.height
    }

    return aDefaultValOrSomethingElseIDontCare
}

// then use reload cells / reload data or smth
SSnowCat commented 3 years ago

I'm using TagListView in a table view with static cells. I calculate my TagListView's height like this:

import Foundation
import TagListView

extension TagListView {

    var height: CGFloat {
        // row count. If tagView doesn't have an item it will be 0
        let count = CGFloat(self.subviews.count)
        // subview (aka row) height. If no row exists 'first' item will be nil, so we set 0.
        let height = self.subviews.first?.frame.height ?? 0
        // margin
        let margin = self.marginY

        // calculate total height.
        // subview count times height + subview count - 1 times margin
        // if count is 0 we don't want to make the view minus margin height
        return CGFloat((count * height) + (count == 0 ? count : count - 1)) * margin)
    }

}

This will give you the exact height of the view.

Now you can set the cell height:

if you are using static cells like me:

@IBOutlet weak var myCell: UITableViewCell

func someFunct() {
    // do stuff
    myCell.frame.size.height = tagList.height
}

if you are using dynamic cells :

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.row == theRowYouWant {
        return tagList.height
    }

    return aDefaultValOrSomethingElseIDontCare
}

// then use reload cells / reload data or smth

thanks , let me try

UrvashiCodiant commented 1 year ago
tableView.reloadData()
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {[weak self] in
            self?.tableView.beginUpdates()
            self?.tableView.endUpdates()
        }

Works perfectly