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
Related
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.
I have a UITableView that holds cells that can show video, html, and images, and a UI of audio playback. That's effectively 3 different cells that could potentially be in the tableView in any given point in time. Cells of the same type can have different heights. That's the problem I'm trying to solve. Out of all the tutorials I've watched/read through, none taught me how to set the calculate then set the heights dynamically. I've only read stuff that show you how to tableViews with different cells that have static heights. Any suggestions on how to solve this problem?
Apply auto-layout in table view cell for cell-items and bound it with both top and bottom and use estimatedHeightForRowAt as:
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
Or you can manually set the height for different rows as:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50 // rather than 50 return height you need to set
}
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.
I wanna get like this:
I am using a custom UITableViewCell where I download images asynchronously with Alamofire from within the cell.
The images appear after the cell was loaded from within the UITableviewController.
Some images do not exist. So the cell should be collapsed and show only text if there is no image present.
How can I achieve to resize the cell when the image is present?
(All images should appear in the same height and full width.
What I already tried is something like this in my TableViewController:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
But the result is pretty ugly:
I am new to IOS and anyhow i have implemented the FZAccordion from HERE. Now my problem is when i have a long text in header section and cells it goes beyond the bounds.So how can i get rid of this problem so that no matter how long is the text it always fits in the screen.
Thank you.
You can use
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override func tableView(_ tableView: UITableView,estimatedHeightForRowAtindexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension}
This will automatically resizes your text in your cells.