I have a custom tableViewCell and inside of that I have an emailText, image, and commentText. The problem is when I set the constraints to "Reset to suggested Constraints" it shows the images like a default cell, very narrow like row height 30 or 40. and I can only see ver little part of the image and I cannot even see the email and comment ever. If I give my own constraints then I can only see email and comment and never see any of the image. How can I fix this issue? this is my code below and I will try to show what I get as a result in pictures and constraints in pictures because I set them in storyboard.
import UIKit
import Firebase
import FirebaseFirestore
import SDWebImage
class FeedsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
#IBOutlet weak var tableView: UITableView!
var postArray = [POST]()
// var emailArray = [String]()
// var commentArray = [String]()
// var imageArray = [String]()
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
fetchFirebaseData()
}
func fetchFirebaseData() {
let firestoreDatabase = Firestore.firestore()
firestoreDatabase.collection("POST").order(by: "Date", descending: true).addSnapshotListener { snapshot, error in
if error != nil {
print(error?.localizedDescription)
} else {
if snapshot?.isEmpty != true && snapshot != nil {
// self.emailArray.removeAll(keepingCapacity: false)
// self.commentArray.removeAll(keepingCapacity: false)
// self.imageArray.removeAll(keepingCapacity: false)
self.postArray.removeAll()
for document in snapshot!.documents {
if let imageURL = document.get("imageUrl") as? String {
if let comment = document.get("comment") as? String {
if let email = document.get("email") as? String {
let post = POST(email: email, comment: comment, image: imageURL)
self.postArray.append(post)
}
}
}
}
self.tableView.reloadData()
}
}
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return postArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! FeedCell
cell.emailText.text = postArray[indexPath.row].email
cell.commentText.text = postArray[indexPath.row].comment
cell.postImageView.sd_setImage(with: URL(string: self.postArray[indexPath.row].image))
return cell
}
}
edit: after I thought I solved the problem I get these errors in the console
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600001d68780 UIImageView:0x143606760.height == 207 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2023-01-21 12:56:19.477442+0300 PhotoShareApp[26983:294545] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x600001d2d6d0 UIImageView:0x146008eb0.height == 207 (active)>",
"<NSLayoutConstraint:0x600001d2db30 UILabel:0x1460090d0.height == 37 (active)>",
"<NSLayoutConstraint:0x600001d2e2b0 UILabel:0x146009650.height == 48 (active)>",
"<NSLayoutConstraint:0x600001d2dfe0 V:|-(0)-[UILabel:0x146009650] (active, names: '|':UITableViewCellContentView:0x146008cd0 )>",
"<NSLayoutConstraint:0x600001d2e0d0 V:[UILabel:0x146009650]-(NSSpace(8))-[UIImageView:0x146008eb0] (active)>",
"<NSLayoutConstraint:0x600001d2def0 V:[UIImageView:0x146008eb0]-(NSSpace(8))-[UILabel:0x1460090d0] (active)>",
"<NSLayoutConstraint:0x600001d2e1c0 UITableViewCellContentView:0x146008cd0.bottomMargin == UILabel:0x1460090d0.bottom + 27 (active)>",
"<NSLayoutConstraint:0x600001d2e030 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x60000070c1c0'UIViewLayoutMarginsGuide']-(11)-| (active, names: '|':UITableViewCellContentView:0x146008cd0 )>",
"<NSLayoutConstraint:0x600001d2d270 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x146008cd0.height == 346.333 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600001d2d6d0 UIImageView:0x146008eb0.height == 207 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
Ok! I solved my problem by adding a height and leading-trailing constraints to the imageview and finally this is what I get
Related
I know that there is a thread dedicated for asking autosizing table view cell in here: why UITableViewAutomaticDimension not working?
but maybe may case little bit different.
so I want to make autosizing of my table view cell based on the text assigned of my label. I think I have tried to set UITableViewAutomaticDimension and also have tried to set the all constraints (top, bottom, right left) with respect to its superview/ cell container. and I have also set the number of line to be zero like this
here is the code of my VC:
class ChatLogVC: UIViewController {
#IBOutlet weak var chatLogTableView: UITableView!
var messageList = [ChatMessage]()
override func viewDidLoad() {
super.viewDidLoad()
listenForMessages()
chatLogTableView.estimatedRowHeight = UITableView.automaticDimension
chatLogTableView.rowHeight = UITableView.automaticDimension
}
private func listenForMessages() {
// Get data from firebase
let fromId = currentUser.uid
let toId = otherUser.uid
let ref = Database.database().reference(withPath: "/user-messages/\(fromId)/\(toId)")
ref.observe(DataEventType.childAdded, with: { (snapshot) in
let messageDictionary = snapshot.value as? [String : Any] ?? [:]
let message = ChatMessage(dictionary: messageDictionary)
self.messageList.append(message)
self.chatLogTableView.reloadData()
})
}
}
//MARK: - UI Table View Data Source & Delegate
extension ChatLogVC : UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return messageList.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellFrom = tableView.dequeueReusableCell(withIdentifier: "fromChatViewCell", for: indexPath) as! fromChatViewCell
let chatMessage = messageList[indexPath.row]
cellFrom.chatMessageData = chatMessage
cellFrom.otherUserData = otherUser
return cellFrom
}
and here is the table view cell:
class fromChatViewCell: UITableViewCell {
#IBOutlet weak var fromChatLabel: UILabel!
#IBOutlet weak var fromProfilePictureImageView: UIImageView!
var chatMessageData : ChatMessage?
var otherUserData : User?
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
updateUI()
}
func updateUI() {
guard let message = chatMessageData, let otherUser = otherUserData else {return}
guard let url = URL(string: otherUser.profileImageURL) else {return}
fromChatLabel.text = message.text
fromProfilePictureImageView.kf.setImage(with: url, options: [.transition(.fade(0.2))])
}
}
}
I have also tried to connect the datasource and delegate to the VC:
and here is my label constraint:
and I have also set the number of line to be zero:
and here is my problem:
if in my storyboard I set the text of my label using just few word, then the autosizing doesn't work, it seems that it will only show one line of text even though actually the text from firebase is more than one line
result (app running):
but if I set the text on my label using a lot of words, then the autosizing table view cell will work and will show all the string from the firebase database:
it will expand, but the autosizing still doens't work since the label still clipping
what went wrong in here? I am really confused
I have tried to change bottom label constraint priority to 200, sometimes the autosizing worked but the other time it will not. maybe my problem related to asynchrounous problem, I have tried to reload the table view rght after get the massge from firebase. but I don't know the root cause of my problem
I am trying to make expandable cells using combination of UITableViewAutomaticDimension row height and Autolayout of the cells. To make things simple, I started with the following simple code, that I expected to work:
import UIKit
class ViewController: UITableViewController {
let cells = [Cell(), Cell(), Cell()]
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 50
for cell in cells {
cell.tableView = tableView
}
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return cells[indexPath.row]
}
}
class Cell: UITableViewCell {
var cons: NSLayoutConstraint?
var tableView: UITableView?
init() {
super.init(style: .default, reuseIdentifier: nil)
let button = UIButton()
contentView.addSubview(button)
button.addTarget(self, action: #selector(Cell.tapped(_:)), for: .touchUpInside)
button.setTitle("Press me", for: .normal)
button.setTitleColor(.red, for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
// constraining the button to the view, so that buttons height would define cell height
let constraints = [
button.topAnchor.constraint(equalTo: contentView.topAnchor),
button.rightAnchor.constraint(equalTo: contentView.rightAnchor),
button.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
button.leftAnchor.constraint(equalTo: contentView.leftAnchor),
]
NSLayoutConstraint.activate(constraints)
cons = button.heightAnchor.constraint(equalToConstant: 100)
cons?.isActive = true
}
func tapped(_ sender: UIButton) {
// change the height of the button, thus of the contentView too (since the button is constrained to the contentView)
if cons?.constant == 100 {
cons?.constant = 200
} else {
cons?.constant = 100
}
// tell the tableView to redraw itself to apply the change
tableView?.beginUpdates()
tableView?.setNeedsDisplay()
tableView?.endUpdates()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Now this seems to be working, however, I still do get UIViewAlertForUnsatisfiableConstraints warning with the following message:
(
"<NSLayoutConstraint:0x17408c7b0 V:|-(0)-[UIButton:0x109e10290'Press me'] (active, names: '|':UITableViewCellContentView:0x109e0fd90 )>",
"<NSLayoutConstraint:0x17408c8a0 UIButton:0x109e10290'Press me'.bottom == UITableViewCellContentView:0x109e0fd90.bottom (active)>",
"<NSLayoutConstraint:0x17408c990 UIButton:0x109e10290'Press me'.height == 200 (active)>",
"<NSLayoutConstraint:0x17408db10 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x109e0fd90.height == 100 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17408c990 UIButton:0x109e10290'Press me'.height == 200 (active)>
It seems that the estimated (or current) row height collides with the autolayout constraint provided by me. Still, refreshing the tableView using following code will display it as expected:
tableView?.beginUpdates()
tableView?.setNeedsDisplay()
tableView?.endUpdates()
How do I remove the warning?
I am aware that simple changing the priority of the height constraint to 999 will remove the warning, but it seems to me as a hack to remove it, not as a solution. If I am mistaken, please explain. Thanks.
Setting the height constraint priority to 999 may feel like a hack, but according to Apple's docs:
NOTE Don’t feel obligated to use all 1000 priority values. In fact, priorities should general cluster around the system-defined low (250), medium (500), high (750), and required (1000) priorities. You may need to make constraints that are one or two points higher or lower than these values, to help prevent ties. If you’re going much beyond that, you probably want to reexamine your layout’s logic.
Probably a little less than intuitive:
"I want the button height to control the cell height, so lower its priority????"
But, that does appear to be the "correct" way to do it.
Ref: https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/AnatomyofaConstraint.html#//apple_ref/doc/uid/TP40010853-CH9-SW19
Remove the height constraint i.e 200 as it is conflicting with top and bottom constraint.
Hope it helps..
I've unexpected problems with tableviews. It seems that the app quits without a error every time I try to reload my tableviews' data. I know that the array is formed correctly, so there's something wrong with these functions:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView.tag == 1 {
return latest.count
}
else if tableView.tag == 2{
return older.count
}
else {
return 0 //In case of error
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell:UITableViewCell?
if tableView.tag == 1 {
print("Success")
cell = tableView.dequeueReusableCell(withIdentifier: "latestCell")! as UITableViewCell
cell = UITableViewCell(style: UITableViewCellStyle.subtitle,
reuseIdentifier: "latestCell")
cell?.textLabel?.text = latest[indexPath.row]
cell?.detailTextLabel?.text = latestSub[indexPath.row]
cell?.accessoryType = .disclosureIndicator
return cell!
}
else if tableView.tag == 2 {
cell = tableView.dequeueReusableCell(withIdentifier: "olderCell")! as UITableViewCell
cell = UITableViewCell(style: UITableViewCellStyle.subtitle,
reuseIdentifier: "olderCell")
cell?.textLabel?.text = older[indexPath.row]
cell?.detailTextLabel?.text = olderSub[indexPath.row]
cell?.accessoryType = .disclosureIndicator
return cell!
}
else {
return cell!
}
}
The answers before to these type of questions here were about forgetting to set delegates and datasource and so... So I believe this is an appropriate question.
Thanks in advance!
EDIT:
var latest = [String]()
var older = [String]()
var latestSub = [String]()
var olderSub = [String]()
override func viewDidAppear(_ animated: Bool) {
latestTable.reloadData()
olderTable.reloadData()
}
The full log;
2017-02-16 15:57:28.889 NotebookApp[24985:604704] Firebase automatic screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO in the Info.plist
2017-02-16 15:57:28.997 NotebookApp[24985:] Firebase Analytics v.3600000 started
2017-02-16 15:57:28.999 NotebookApp[24985:] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled
2017-02-16 15:57:29.012: FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2017-02-16 15:57:29.020 NotebookApp[24985:] Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
2017-02-16 15:57:29.090 NotebookApp[24985:] The AdSupport Framework is not currently linked. Some features will not function properly.
2017-02-16 15:57:29.180 NotebookApp[24985:] Firebase Analytics enabled
2017-02-16 15:57:45.703779 NotebookApp[24985:604704] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"",
""
)
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
2017-02-16 16:01:34.316879 NotebookApp[24985:604704] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/tuomasnummela/Library/Developer/CoreSimulator/Devices/AA87179A-11E5-4A3A-A63F-B785AA71EC95/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-02-16 16:01:34.317476 NotebookApp[24985:604704] [MC] Reading from private effective user settings.
I kind of didn't think that there would be anything useful here because when the app quits it doesn't take me to the error-page-thing and highlight any code.
What my project looks like after the app has forcedly closed itself.
The things that can go wrong here is it can't find the cell with the reuse identifier that you are passing in the below line
cell = tableView.dequeueReusableCell(withIdentifier: "olderCell")! as UITableViewCell
All you have to do is register the cell with reuse identifier in your viewDidLoad
<olderTableView>.registerClass(UITableViewCell.self, forCellReuseIdentifier: "olderCell")
<latestTableView>.registerClass(UITableViewCell.self, forCellReuseIdentifier: "latestCell")
or
you can simply replace the dequeue and initialization lines with the following
if tableView.tag == 1 {
let reuseId = "latestCell"
let latestCell = tableView.dequeueReusableCell(withIdentifier: reuseId) ?? UITableViewCell(style: .subtitle, reuseIdentifier: reuseId)
latestCell.textLabel?.text = latest[indexPath.row]
latestCell.detailTextLabel?.text = latestSub[indexPath.row]
latestCell.accessoryType = .disclosureIndicator
return latestCell
}
The first error is in the viewDidAppear you must call the super.viewDidAppear(animated), the tableview reload will never fired.
You have a number of errors in func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell. The crash is likely from force unwrapping cell which was nil in the last line.
Here is my stab at cleaning it up. Be sure to register you UITableViewCell subclass with tableView.register(SubtitleCell.self, forCellReuseIdentifier:"latestCell"). Unless there is other code not visible, you can use the same identifier for latestCell and olderCell - they don't seem to be different from the code you've posted
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell:UITableViewCell //can't be optional
if tableView.tag == 1 {
print("Success")
cell = tableView.dequeueReusableCell(withIdentifier: "latestCell", forIndexPath: indexPath) as! SubtitleCell
//cell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "latestCell") //don't call this here, make a subclass of UITableViewCell to set style
cell.textLabel?.text = latest[indexPath.row]
cell.detailTextLabel?.text = latestSub[indexPath.row]
cell.accessoryType = .disclosureIndicator
return cell
}
else if tableView.tag == 2 {
//same comments as above
cell = tableView.dequeueReusableCell(withIdentifier: "olderCell", for: indexPath) as! SubtitleCell
cell.textLabel?.text = older[indexPath.row]
cell.detailTextLabel?.text = olderSub[indexPath.row]
cell.accessoryType = .disclosureIndicator
return cell
}
else {
cell = tableView.dequeueReusableCell(withIdentifier: "latestCell", forIndexPath: indexPath)
return cell //you were returning nil here - need to return a cell
}
}
Here is an example of how to init the correct cell style
class SubtitleCell: UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
}
I'm going through Stanford's cs193p. Assignment 4 has us create a custom UITableVIewCell and load a picture from the web into a UIImageView inside the cell.
My UIImageView and my Cell have their content mode set to Aspect Fit on the story board.And the ImageView is set on autolayout to be hugging the cell.
And yet when the picture first loads, it will bleed out of the UIImageView. When I click on it, it will correctly aspect fit.
I tried setting the content mode in code just before assigning the image, but that also didn't work. I also tried calling layoutSubviews() and setNeedsLayout right after assigning the image, and while that helps by actually showing the image (as opposed to showing nothing until the user clicks the cell), it still shows in the wrong size until the user clicks it.
This is the code for the cell:
import UIKit
class ImageTableViewCell: UITableViewCell {
#IBOutlet weak var pictureView: UIImageView!
var pictureURL: URL? {
didSet {
fetchImage()
}
}
fileprivate func fetchImage() {
if let url = pictureURL {
pictureView.image = nil
let queue = DispatchQueue(label: "image fetcher", qos: .userInitiated)
queue.async { [weak weakSelf = self] in
do {
let contentsOfURL = try Data(contentsOf: url)
DispatchQueue.main.async {
if url == self.pictureURL {
weakSelf?.pictureView?.image = UIImage(data: contentsOfURL)
weakSelf?.layoutSubviews()
print("loaded")
}
}
} catch let exception {
print(exception.localizedDescription)
}
}
}
}
}
This is the code that loads the cell on its TableViewController:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = UITableViewCell()
switch indexPath.section {
case 0:
cell = tableView.dequeueReusableCell(withIdentifier: "imageCell", for: indexPath)
if let imageCell = cell as? ImageTableViewCell {
imageCell.pictureURL = tweet?.media[indexPath.row].url
// other stuff not programmed yet
}
return cell
The code that gives me the cell's height:
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0 && tweet != nil {
let media = tweet?.media[indexPath.row]
return tableView.frame.width / CGFloat(media!.aspectRatio)
}
return UITableViewAutomaticDimension
}
I'm sorry for pasting all this code, but I have no idea where the problem is so I'm putting everything I can this might be related.
You should set content mode first and then you should set the frame of your imageview, so once you should try to set content mode in awakeFromNib of tableview subclass or from cellforrowatindexpath before setting image to it!
Or you can set your content mode from interface builder (from storyboard!) - > select your imageview - > fro attribute inspector - > select mode(under view) to Aspect fit
Well, following an answer on reddit, I deleted the table view controller and remade it, setting all the outlets again. It worked, I guess it was a problem in Xcode?
So if you're having a problem like this, try remaking your storyboard.
I attempted to follow what I've read here on how to content-fit UITableView cells. However, the cells are still clipping content. See below:
The cell: (Connected to my custom cell class)
The constraints: (All constraints set to the ContentView)
The custom cell class:
import UIKit
class S360SSessionTableCell: UITableViewCell {
#IBOutlet var iconImg:UIImageView!
#IBOutlet var locationLbl:UILabel!
#IBOutlet var dateLbl:UILabel!
#IBOutlet var startTimeLbl:UILabel!
#IBOutlet var endTimeLbl:UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
The implementation:
These are the only table related methods. In addition, I have this in viewDidLoad: myTableView.estimatedRowHeight = 100.0
//Table Datasource
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:S360SSessionTableCell? = tableView.dequeueReusableCellWithIdentifier("S360SSessionTableCell") as? S360SSessionTableCell
if ((cell == nil)){
tableView.registerNib(UINib(nibName: XIBFiles.SESSIONTABLECELL, bundle: nil), forCellReuseIdentifier: "S360SSessionTableCell")
cell = tableView.dequeueReusableCellWithIdentifier("S360SSessionTableCell") as? S360SSessionTableCell
}
var session = sessions[indexPath.row]
cell!.locationLbl.text = (session["location"] as! String) + " - " + "Court " + (String(session["subname"]))
dateFormatter.dateFormat = "MMM. dd, yyyy"
cell!.dateLbl.text = dateFormatter.stringFromDate(session["startDate"] as! NSDate)
dateFormatter.dateFormat = "hh:mm a"
cell!.startTimeLbl.text = dateFormatter.stringFromDate(session["startDate"] as! NSDate)
cell!.endTimeLbl.text = dateFormatter.stringFromDate(session["endDate"] as! NSDate)
return cell!
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sessions.count
}
However, the cells still appear clipped, like so:
I am targeting iOS9.3, and it was my understanding that using AutoLayout, the default for cell height was an automatic content fit, one of the perks of the iOS8.0 changes made.
Where am I going wrong with this? I want the cells to fit the content they have and not clip it.
There should be a direct line of constraints from the top of the cell to the bottom. In other words, This image from Ray Wenderlich illustrates that very well
From Ray Wenderlich
Furthermore, you need a clear line of constraints going from the top to the bottom of the contentView. This ensures that auto layout correctly determines the height of the contentView based on its subviews.
Apart from given answer you could try other way as below,
Apply the constraints accordingly to your subviews and labels and in viewdidappear do the following,
tableView.estimatedRowHeight = 85.0
tableView.rowHeight = UITableViewAutomaticDimension
Please refer the following link for more details,
Working with Self-Sizing Table View Cells.
You can also check the following for a sample
Table View Cells with Varying Row Heights