custom UITableviewcell height not set correctly
You can use self-sizing cells in iOS 8 (Swift code):
tableView.estimatedRowHeight = 88.0
tableView.rowHeight = UITableViewAutomaticDimension
Two tutorials list below:
- Understanding Self Sizing Cells and Dynamic Type in iOS 8
- iOS 8: Self Sizing Table View Cells with Dynamic Type
getting the height of the custom cell in UITableViewCell
You can use Autolayout for the same and get free from all the coding part. Just set the constraint of the inner view in association with the cell and then right the following code.
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:ChatSenderTableViewCell = (tableView.dequeueReusableCell(withIdentifier: "ChatSenderTableViewCell", for: indexPath) as? ChatSenderTableViewCell)!
cell.LabelChatMessage.text = "Your Message"
cell.LabelChatMessage.numberOfLines = 0
cell.LabelChatMessage.sizeToFit()
return cell
}
I am using a custom cell name ChatSenderTableViewCell to create a bubble like effect containing a label for messages send or receive.
Custom UITableViewCell Height
You can change the height of all of your cells in the definition of the tableView, but to set them individualy you have to use the delegate method. It's confusing that you can set it in IB but it is for display purposes only and not used at runtime.
Related Topics
Get the Current Scroll Position of a Swiftui Scrollview
How to Pass Data Between View Controllers in Swift
Didselectrowatindexpath Not Working, Swift 3
Uitableviewcell, Show Delete Button on Swipe
Difference Between Uiviewcontentmodescaleaspectfit and Uiviewcontentmodescaletofill
How to See Saved Nsuserdefaults
How to Simultaneously Satisfy Constraints, Will Attempt to Recover by Breaking Constraint
Delete Keychain Items When an App Is Uninstalled
Proper Use of Beginbackgroundtaskwithexpirationhandler
Ios 6: How to Restrict Some Views to Portrait and Allow Others to Rotate
How to Load Local HTML File into Uiwebview
Uicollectionview - Dynamic Cell Height
How to Put Buttons Over Uitableview Which Won't Scroll With Table in Ios
Swiftui App Life Cycle Ios14 Where to Put Appdelegate Code
Uiscrollview Pauses Nstimer Until Scrolling Finishes