I am having issues getting rid of a pesky NSAutoresizingMaskLayoutConstraint that is breaking the auto-layout width constraints of some UITextView.
I have a UITableviewCell that contains a text view, and the text view's height is dynamically set based on the content of the text view's text using
self.table.sectionHeaderHeight = UITableView.automaticDimension;
self.table.estimatedSectionHeaderHeight = 200;
This works pretty well when auto-layout is used (I am setting my constraints via the interface and not code). However, I noticed that the widths of the text views are conflicting with NSAutoresizingMaskLayoutConstraint - and the end result is the width constraint on my text view is being removed.
[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)
(
"<NSAutoresizingMaskLayoutConstraint:0x6000012ff070 h=--& v=--& UITextView:0x7fde2f09e600'At teenfvfed'.width == 89.5 (active)>",
"<NSLayoutConstraint:0x600001292210 UITextView:0x7fde2f09e600'At teenfvfed'.width == 293 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600001292210 UITextView:0x7fde2f09e600'At teenfvfed'.width == 293 (active)>
The common answer I see online is to add translatesAutoresizingMaskIntoConstraints = false on the text view, but this doesn't have any effect and NSAutoresizingMaskLayoutConstraint remains. Any help would be greatly appreciated to remove this!
Try this:
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.text.translatesAutoresizingMaskIntoConstraints = false
cell.setNeedsLayout()
cell.layoutIfNeeded()
}
Related
I have an app, when I click on my profile page, I kept getting these errors in my console
I have tried
This is the entire constraint that I have on my profile page
I kept getting
john
jane
andrew
2018-07-31 11:58:46.821640-0400 tableInTabbed[4355:5682078] [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:0x604000281130 UIImageView:0x7ff91cf1d030.width == 70 (active)>",
"<NSLayoutConstraint:0x6040002812c0 UIImageView:0x7ff91cf1d030.width == UIImageView:0x7ff91cf1d030.height (active)>",
"<NSLayoutConstraint:0x604000280d20 UITableViewCellContentView:0x7ff91cf1c7f0.bottomMargin == UIImageView:0x7ff91cf1d030.bottom + 52.67 (active)>",
"<NSLayoutConstraint:0x6040002815e0 UIImageView:0x7ff91cf1d030.top == UITableViewCellContentView:0x7ff91cf1c7f0.topMargin + 29.33 (active)>",
"<NSLayoutConstraint:0x60c000290040 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7ff91cf1c7f0.height == 168 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6040002812c0 UIImageView:0x7ff91cf1d030.width == UIImageView:0x7ff91cf1d030.height (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-07-31 11:58:46.822304-0400 tableInTabbed[4355:5682078] [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:0x604000280d20 UITableViewCellContentView:0x7ff91cf1c7f0.bottomMargin == UIImageView:0x7ff91cf1d030.bottom + 52.67 (active)>",
"<NSLayoutConstraint:0x6040002815e0 UIImageView:0x7ff91cf1d030.top == UITableViewCellContentView:0x7ff91cf1c7f0.topMargin + 29.33 (active)>",
"<NSLayoutConstraint:0x604000281310 UIImageView:0x7ff91cf1d030.height == 70 (active)>",
"<NSLayoutConstraint:0x60c000290040 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7ff91cf1c7f0.height == 168 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x604000281310 UIImageView:0x7ff91cf1d030.height == 70 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-07-31 11:58:46.822846-0400 tableInTabbed[4355:5682078] [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:0x60c00028fa00 UIImageView:0x7ff91cc140c0.width == 70 (active)>",
"<NSLayoutConstraint:0x60c00028ff00 UIImageView:0x7ff91cc140c0.width == UIImageView:0x7ff91cc140c0.height (active)>",
"<NSLayoutConstraint:0x60c00028a8c0 UITableViewCellContentView:0x7ff91cc13cb0.bottomMargin == UIImageView:0x7ff91cc140c0.bottom + 52.67 (active)>",
"<NSLayoutConstraint:0x60c000289b50 UIImageView:0x7ff91cc140c0.top == UITableViewCellContentView:0x7ff91cc13cb0.topMargin + 29.33 (active)>",
"<NSLayoutConstraint:0x60c000290900 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7ff91cc13cb0.height == 168 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60c00028ff00 UIImageView:0x7ff91cc140c0.width == UIImageView:0x7ff91cc140c0.height (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-07-31 11:58:46.823293-0400 tableInTabbed[4355:5682078] [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:0x60c00028a8c0 UITableViewCellContentView:0x7ff91cc13cb0.bottomMargin == UIImageView:0x7ff91cc140c0.bottom + 52.67 (active)>",
"<NSLayoutConstraint:0x60c000289b50 UIImageView:0x7ff91cc140c0.top == UITableViewCellContentView:0x7ff91cc13cb0.topMargin + 29.33 (active)>",
"<NSLayoutConstraint:0x60c00028fb90 UIImageView:0x7ff91cc140c0.height == 70 (active)>",
"<NSLayoutConstraint:0x60c000290900 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7ff91cc13cb0.height == 168 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60c00028fb90 UIImageView:0x7ff91cc140c0.height == 70 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-07-31 11:58:46.823961-0400 tableInTabbed[4355:5682078] [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:0x60c000290ae0 UIImageView:0x7ff91cc16a40.width == 70 (active)>",
"<NSLayoutConstraint:0x60c000290b30 UIImageView:0x7ff91cc16a40.width == UIImageView:0x7ff91cc16a40.height (active)>",
"<NSLayoutConstraint:0x60c000290cc0 UITableViewCellContentView:0x7ff91cc16840.bottomMargin == UIImageView:0x7ff91cc16a40.bottom + 52.67 (active)>",
"<NSLayoutConstraint:0x60c000290d60 UIImageView:0x7ff91cc16a40.top == UITableViewCellContentView:0x7ff91cc16840.topMargin + 29.33 (active)>",
"<NSLayoutConstraint:0x6040002822b0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7ff91cc16840.height == 168 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60c000290b30 UIImageView:0x7ff91cc16a40.width == UIImageView:0x7ff91cc16a40.height (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-07-31 11:58:46.824333-0400 tableInTabbed[4355:5682078] [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:0x60c000290cc0 UITableViewCellContentView:0x7ff91cc16840.bottomMargin == UIImageView:0x7ff91cc16a40.bottom + 52.67 (active)>",
"<NSLayoutConstraint:0x60c000290d60 UIImageView:0x7ff91cc16a40.top == UITableViewCellContentView:0x7ff91cc16840.topMargin + 29.33 (active)>",
"<NSLayoutConstraint:0x60c000290b80 UIImageView:0x7ff91cc16a40.height == 70 (active)>",
"<NSLayoutConstraint:0x6040002822b0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7ff91cc16840.height == 168 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60c000290b80 UIImageView:0x7ff91cc16a40.height == 70 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
This is what I have
//
// ProfileViewController
// tableInTabbed
//
// Copyright © 2018 LR Web Design. All rights reserved.
//
import UIKit
class ProfileViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let profiles = ["john", "jane", "andrew"]
let devicesInProfile = ["3", "5", "10"]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (profiles.count)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ViewControllerTableViewCell
cell.profileImg.image = UIImage(named: profiles[indexPath.row] + ".jpg")
cell.profileName.text = profiles[indexPath.row]
print(profiles[indexPath.row])
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
I just want to get rid of the error message.
Update
#Sandeep, after trying your answer, I ended up with this final constraint
This is the result
Can you please suggest a bit more ?
Step 1:
Drag a View to your cell and apply horizontally and vertically center constraints to to your view (This will show few constraint breaks but hang on a bit)
Step 2:
Drag imageView to view and apply height constraint/ aspect ratio/ leading / height and bottom constraint as shown
Step 3:
Drag UILabel to View preferably right side of ImageView and apply trailing constraint and leading constraint to label. Leading constraint will be to content view of cell while leading constraint to UIImageView.
Trailing Constraint to Label
Now add Leading constraint to UIImageView (Control drag from label to imageView and select horizontal spacing)
Finally control drag from label to imageView again and select center vertically
That should be it :)
If everything is fine final constraints should look like
Hope this helps
What have you did in your code seems to be fine, but it has nothing to do with what have you seen in the console.
First, you should know that red constraints means that there is something wrong, more specifically it means that the interface builder is unable to recognize what to achieve because there is at least one constraint missed (and that's why you are seeing these complains on the console).
Therefore, I would highly recommend to avoid following the approach of "Adding Missing Constraints" or "Reset to Suggested Constraints", it is not an elegant option to deal with constraints; Most of the time, even if they didn't add red (missing) constraints, it won't leads to the expected result, which seems to be logical because it can't be so magical to read your mind thoughts and translate it, they could be more than just one aspect for determining the way of how to setup the constraints! Instead, do it by your self, that's the good approach for achieving what's exactly it should look/behave. Keep in mind that it is not just one static way to do it, after getting understanding the that Auto Layout works you figure that there is more than one way to achieve it.
In general, the expected result is to see blue lines (constraints) instead of red or orange.
Now, because it might be broad to describe how to setup your constraints (Auto Layout), I would suggest to check: Understanding Auto Layout from Apple, it is a very good place to start with.
1- Make sure that only one path of elements from top to bottom is hooked to the contentView , if you see red lines , disconnect bottom constraint and change middle items constraints , then re-hook it again
2- Set bottom most constraint priority to 999
3- Set leading to the imageView and only the bottom - most element should be hooked to the contentView's bottom
//
Blue lines here should only be constraints with img width&height
//
Set this in viewDidLoad
tableView.estimatedRowHeight = 200;
tableView.rowHeight = UITableViewAutomaticDimension;
I have a UITableViewCell with collectionView inside it. constraint are pretty simple leading 0 , trailing 0 , top 10 and bottom 10 and height constraint of UICollection view is 160 . Connected an IBOutlet to height constraint. In cell for row I am updating the heigth constraint.
But getting error in debug
Code of cell for row is
func videoCell(for tableView:UITableView ,with indexPath:IndexPath , videos:[VideoCollectionViewCellConfigure] ) -> VideoTableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "VideoTableViewCell", for: indexPath) as! VideoTableViewCell
cell.videoConfigurators = videos
cell.collectionCellClickedBlock = self.videoCollectionCellClicked(_:_:)
if videos.count > 0 {
let video = videos[0]
cell.videoCollectionViewHeightConstraint.constant = video.height
}
cell.videoCollectionView.reloadData()
return cell
}
2018-04-16 12:42:10.815998+0530 CineBee[5280:74417] [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:0x6000006878a0 UICollectionView:0x7f86109c4c00.height
== 180 (active)>",
"<NSLayoutConstraint:0x604000885870 V:[UICollectionView:0x7f86109c4c00]-(10)-| (active, names: '|':UITableViewCellContentView:0x7f8615803ca0 )>",
"<NSLayoutConstraint:0x604000888de0 V:|-(10)-
[UICollectionView:0x7f86109c4c00] (active, names: '|':UITableViewCellContentView:0x7f8615803ca0 )>",
"<NSLayoutConstraint:0x60400088dde0 'UIView-Encapsulated-Layout-Height'
UITableViewCellContentView:0x7f8615803ca0.height == 180.5 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000006878a0
UICollectionView:0x7f86109c4c00.height == 180 (active)>
Try this
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
var defaultHeight = /*your default height*/
if videos.count > 0 {
let video = videos[0]
return video.height + 10 + 10 // video height + top padding + bottom padding
}
return defaultHeight
}
Also remove the collectionView height constraint from the Interface builder. Now you don't have to set constraint in the cellForItemAtIndexPath.
According to your error report, it seems like the case I was attempting to address in this SO question. If the conflicting constraints contain UIView-Encapsulated-Layout-Height it means the conflict arises during calculating dynamic height based on autolayout. Just lower one of the vertical constraints priority to 999 - if the code works, it's ok and you are good to go.
A collection view is placed in the upper part of the screen. The collection view is horizontal and has one row.
The row can contain multiple collection view cells.
Each cell inside has UIImageView. The UIImageView is meant to contain an UIImage.
The UIImage is a photo. A photo might be of a different size, but inside the collection view cell it has to be squared with aspect ratio 1:1.
The problem is making the collection view cell to be of square size, where the side of the square should be equal to the height of the collectionView. And the UIImageView should take whole space of the collection view cell making the UIImage squared.
The UIImageView has constraints set ratio 1:1; and the top, leading, and bottom of collection cell.
The collection cell has its size calculated programatically:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let size = collectionView.bounds.size.height
return CGSize(width: size, height: size)
}
I get the following error in the debugger:
[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)
(
"<NSAutoresizingMaskLayoutConstraint:0x6180000968f0 h=--& v=--& UIView:0x7f8c3f61e940.width == 217 (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x618000096990 h=--& v=--& UIView:0x7f8c3f61e940.height == 100 (active)>",
"<NSLayoutConstraint:0x618000096030 UIImageView:0x7f8c3f61eae0.width == UIImageView:0x7f8c3f61eae0.height (active)>",
"<NSLayoutConstraint:0x618000096120 H:[UIImageView:0x7f8c3f61eae0]-(0)-| (active, names: '|':UIView:0x7f8c3f61e940 )>",
"<NSLayoutConstraint:0x618000096170 V:[UIImageView:0x7f8c3f61eae0]-(0)-| (active, names: '|':UIView:0x7f8c3f61e940 )>",
"<NSLayoutConstraint:0x6180000961c0 H:|-(0)-[UIImageView:0x7f8c3f61eae0] (active, names: '|':UIView:0x7f8c3f61e940 )>",
"<NSLayoutConstraint:0x618000096210 V:|-(0)-[UIImageView:0x7f8c3f61eae0] (active, names: '|':UIView:0x7f8c3f61e940 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x618000096030 UIImageView:0x7f8c3f61eae0.width == UIImageView:0x7f8c3f61eae0.height (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
How to make it work?
You don't need both the aspect ratio constraint and the right constraint. One is enough. But, logically if you had both they shouldn't conflict if your size calculations is correct.
Your calculation looks good. Therefore, the thing in mind that could effect your calculations is the (header size, footer size, spacing insets)
Another thing that could affect this is reloading collection view data
on viewDidLoad before the uiviews complete layouting.
So, my table view displays images. Every cell is basically an image filling out the cells entire contentView. As the images come with different aspect ratios, I need my cells to be adjusting their height depending on the table views width and the aspect ratio of the image. I've followed this Ray Wenderlich tutorial but now get a constraint conflict. The image is resized by altering the imageViews height constraint e.g. myImageViewHeight.constant = tableView.frame.width / aspectRatio
2016-06-16 13:56:25.823 MyApp[92709:5649464] 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:0x7fbcdaf5c190 V:[UIImageView:0x7fbcdaf5c300(303)]>",
"<NSLayoutConstraint:0x7fbcdaf5b460 V:|-(0)-[UIImageView:0x7fbcdaf5c300] (Names: '|':UITableViewCellContentView:0x7fbcdaf52230 )>",
"<NSLayoutConstraint:0x7fbcdaf5b4b0 V:[UIImageView:0x7fbcdaf5c300]-(0)-| (Names: '|':UITableViewCellContentView:0x7fbcdaf52230 )>",
"<NSLayoutConstraint:0x7fbcdaf5e550 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fbcdaf52230(100)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fbcdaf5c190 V:[UIImageView:0x7fbcdaf5c300(303)]>
The image view has the following constraints and has the cells contentView as superview.
In the table view controller class, I'm using
self.tableView.estimatedRowHeight = 80
self.tableView.rowHeight = UITableViewAutomaticDimension
I've also tried this - same result.
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
I'm guessing that I have to get rid of the 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fbcdaf52230(100)]>" but how? Also, does anybody know some kind of documentation/tutorials on how to properly create table views with dynamic content that not only cover having a bunch of labels inside the cell? My code works just fine if the image view is replaced by a label...
You implementation is correct don't change anything in your code or any of your constraints.Removing the warning is easy just select the height constraint and lower its priority from 1000 to 999 it will fix your warning.If it still comes, let me know.
It is an old question but I put this just for the record.
The problem here is the estimated hight, 80, that is lower then the computed hight, 100.
Changing the estimated hight to >=100 should fix this warning.
With the release of iOS8 I have designed my table view with cells taking advantage of self sizing cells. But I need my tables to work in iOS7 as well. How do I do that? Is there a way to check whether self sizing cells is supported or not in runtime, or can I implement some table delegate methods in my controller which will not be called in iOS7?
If I try my table with self sizing cells in iOS7 I get errors on the console like this:
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)
(
"<NSLayoutConstraint:0x7fc912d1d5a0 V:|-(>=11)-[UILabel:0x7fc912d13900] (Names: '|':UITableViewCellContentView:0x7fc912d13400 )>",
"<NSLayoutConstraint:0x7fc912d1d6b0 V:[UILabel:0x7fc912d13900]-(11)-| (Names: '|':UITableViewCellContentView:0x7fc912d13400 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7fc912d24d80 h=--& v=--& V:[UITableViewCellContentView:0x7fc912d13400(0.5)]>"
)
This is the solution I have found thus far, but it requires checking for specific version number rather than capability. You only set UITableViewAutomaticDimension if you have iOS 8 or higher as version:
override func viewDidLoad() {
if NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1 {
self.tableView.estimatedRowHeight = 80
self.tableView.rowHeight = UITableViewAutomaticDimension
}
}
For iOS 7 you need to calculate a height for each cell. But if you are on iOS 8 you can return UITableViewAutomaticDimension as the height:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1 {
return UITableViewAutomaticDimension
}
return 50 // Or whatever calculated value you need for cell height
}
For iOS versions older than 8.0, you can always write the usual heightForRowAtIndexPath method where you create a cell, run an auto layout pass on it and then return the actual height.