self sizing tableview cell is not estimating heigh as expected - ios

I have a tableView cell with constrains that works nice in Xcode 9, and iOS 10, after upgrate to iOS 12 and Xcode 10 the self sizing stop working, tableView was unable to determinate the cell size.
The cell designing is this with all constraints:
So setting by code the automatic dimension
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 196
}
The result is that I have to use the height for row with a number instead of automaticDimension to see the cell in tableView. So, I'm missing a constrain here or what.

Related

How to make last row to cover the remaning unoccupied space of tableview

I have a tableview , it has two rows.
Tableview's height is 700. The first row height is 150 and the second row height is 100 but I'd like the second cell to cover the rest of the space in tableview.
I know I can use the below for tableview height. But I'd like to
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
Simply, just replace this method
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let tblHeight = infoTable.bounds.size.height
return indexPath.row == 0 ? 150 : tblHeight - 150
}
just change infoTable with your table name.

iOS 14 dequeueReusableCell issues

I have a chat view where I'm using tableview to display different custom cells for incoming and outgoing messages and the app was working fine till ios 13,
But as soon as I updated the phone OS to ios 14 its giving me issue
the issue is seems to be likely in dequeueReusableCell function, bigger cells taking height if smaller cells and smaller taking height of bigger cell instead of their own cell content
I have used the table height like this
IN VIEW DIDLOAD FUNCTION
self.chatTableView.estimatedRowHeight = 44
self.chatTableView.rowHeight = UITableView.automaticDimension
internal func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
Also tried to use
cell.setNeedsLayout()
cell.layoutIfNeeded()
at differenct places like when the heightForRowAt, cellForRowAtIndexPAth and willdisplayCellForRowAtIndexPAth get called but getting the same issue

Dynamically resizing cell with a tableView within it (iOS)

I have a tableView, and within each UITableViewCell (call this parentCell), I have another tableView which has cells (call this childCell). I am using UITableViewAutomaticDimension to dynamically resize both of the cells height. I am successfully able to resize the height of the childCell this way, however, I am not able to apply UITableViewAutomaticDimension to the parentCell, since there when heightForRow is called, the childCell's height have yet to be estimated.
Is it possible to use UITableViewAutomaticDimension to estimate the parent cells height, which will be the height of all the childCell's height added together? Or am I going to have to do this manually?
//in ViewDidLoad
parentTableView.rowHeight = UITableViewAutomaticDimension
//in ParentCell's tableView's cell for row
cell.childTableView.rowHeight = UITableViewAutomaticDimension
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
The only way to do this was to use sections instead of placing a tableview within a cell.

TableViewCell Auto height issue

I am writing an iOS app.
User types in movie search keywords and it fetches data from omdbapi.com and displays movies in tableview.
Issue is that that table view cell isn't getting displayed correctly.
Project URL:
project on onedrive
I tried using every autolayout method but, its not working.
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension;
}
You need to set estimate method for table height too. so place these method for height calculation and also check your cell constraint.
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
Hope this will help you.

Xcode Table View Cells won't resize height

I am trying to have a UITableView with different sized prototype cells.
I set the row height in my Table View to 243. The first and second cells' individual row height are set to 243 and 465, respectively. When I run my app, both cells appear at 243 height.
Here is what I have tried:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 25
}
//does not change cell height
And:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 25
}
//Method does not override any method from its superclass
How can I configure my project to successfully resize the second cell?
The signature of the delegate method has changed in Swift 3. It needs to be:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 1 {
return 465.0
} else {
return 243.0
}
}
With the wrong signature the table view doesn't know you've implemented the method so it never gets called.

Resources