Reputation: 2017
here is a storyboard image. i have take a dynamic tableviewcell I have tried with drag and drop UITableViewCell
and change row height from the storyboard, it cannot expanded cell height at runtime.
In Xcode 9.0.1
and Swift 4
, I am facing issues regarding cell height not increasing at runtime.so, pls help me for solving this issue.
Upvotes: 3
Views: 6292
Reputation: 79636
To set automatic dimension for row height & estimated row height, ensure following steps to make, auto dimension effective for cell/row height layout.
UITableViewAutomaticDimension
to rowHeight & estimatedRowHeightheightForRowAt
and return a value UITableViewAutomaticDimension
to it)-
@IBOutlet weak var table: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Don't forget to set dataSource and delegate for table
table.dataSource = self
table.delegate = self
// Set automatic dimensions for row height
table.rowHeight = UITableViewAutomaticDimension
table.estimatedRowHeight = UITableViewAutomaticDimension
}
// UITableViewAutomaticDimension calculates height of label contents/text
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
For label instance in UITableviewCell
Upvotes: 8
Reputation: 24341
Try this:
1. Implement UITableViewDelegate
methods:
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat
{
return 200
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
return UITableViewAutomaticDimension
}
2. Apply proper constraints
to your UITableViewCell
so that it can correctly calculate its own height
. It is must for right UITableViewCell
UI to appear. Any issue in autolayout
might cause your cell UI to behave in an unexpected manner.
Upvotes: 2