logo
down
shadow

UITableViewCell constraints breaking when adding a new cell


UITableViewCell constraints breaking when adding a new cell

By : user2173481
Date : October 20 2020, 08:10 PM
this one helps. I have a UITableViewController that a combinations of 3 different cell types. I have an odd bug that occurs when pushing a new cell to the table view and calling reload data. , These three constraints are in conflict:
code :
"<NSLayoutConstraint:0x60000201ccd0 UIImageView:0x7ffb7bd4d740.trailing == 
UILayoutGuide:0x600003a79ea0'UIViewLayoutMarginsGuide'.trailing   (active)>",
"<NSLayoutConstraint:0x60000201c3c0 UIView:0x7ffb7bd4d970.leading == 
UILayoutGuide:0x600003a79ea0'UIViewLayoutMarginsGuide'.leading + 15   (active)>",
"<NSLayoutConstraint:0x6000020194a0 H:[UIImageView:0x7ffb7bd4d740]-(15)- 
[UIView:0x7ffb7bd4d970]   (active)>",


Share : facebook icon twitter icon
Constraints of views in custom UITableViewCell getting reset on cell reuse

Constraints of views in custom UITableViewCell getting reset on cell reuse


By : Eelface Jackson
Date : March 29 2020, 07:55 AM
like below fixes the issue Well, I managed to find a workaround. What I ended up doing was setting the translateAutoresizingMaskIntoConstraints flag to false on the content view of my custom table cell. This caused the imageView to no longer move around after cell reuse but it did move every subview down so that they were only half visible. Adding some additional constraints using the Storyboard fixed this.
Add a view from a xib file to a UITableViewCell adding constraints

Add a view from a xib file to a UITableViewCell adding constraints


By : Anil Kondi
Date : March 29 2020, 07:55 AM
Hope this helps Finally I find the issue:
the problem is in the xibSetup() method because I load the xib but I don't set the constraints! So my new method is:
code :
func xibSetup() {
    let myView = loadViewFromNib()

    myView.translatesAutoresizingMaskIntoConstraints = false

    self.addSubview(myView)

    let leading = NSLayoutConstraint(item: myView, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: myView.superview, attribute: NSLayoutAttribute.Leading, multiplier: 1, constant: 0)
    self.addConstraint(leading)

    let bottom = NSLayoutConstraint(item: myView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: myView.superview, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0)
    self.addConstraint(bottom)

    let trailing = NSLayoutConstraint(item: myView, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: myView.superview, attribute: NSLayoutAttribute.Trailing, multiplier: 1, constant: 0)
    self.addConstraint(trailing)

    let top = NSLayoutConstraint(item: myView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: myView.superview, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0)
    self.addConstraint(top)

}
Two states on UITableViewCell and AutoLayout breaking constraints

Two states on UITableViewCell and AutoLayout breaking constraints


By : JohnnyPgood
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , A better solution in you case would be using two cells with different identifiers - one containing view A, another one containing views A,B. Then you could .dequeueReusableCell(withIdentifier: %CELL_A_OR_CELL_B_IDENTIFIER%, for: indexPath) depending on your needs.
Less suitable solution is to use stack view or adjust your constraints. In both cases the only way to avoid conflicts and prevent incorrect layout is to properly set constraint priorities. I would try to set constraint in circle priority to something less 1000 (like 990)
Adding Constraints to UITableViewCell

Adding Constraints to UITableViewCell


By : Amruta
Date : March 29 2020, 07:55 AM
like below fixes the issue Your noteTextLabel has no leading or trailing constraints. The leading constraint should be to the superView and the trailing constraint should be to the left side of the button.
Your flagButton should have top and trailing constraints, where both are to the superView. Or the button could have a centerY constraint and a trailing constraint instead, where the centerY constraint is the same as the superView's and the trailing constraint is to the superView. The button should also have width and height constraints.
adding subviews in uitableviewcell breaks constraints

adding subviews in uitableviewcell breaks constraints


By : user3305234
Date : March 29 2020, 07:55 AM
This might help you You forgot to set translatesAutoresizingMaskIntoConstraints = false on the label — as the error message quite plainly points out.
Related Posts Related Posts :
  • Managing cookies for a domain in Associated Domains
  • Array items showing error in IOS
  • Saving asynchronously downloaded files' contents to SQLITE
  • Swift 4 - animating both alpha and constraint affects other components alpha value
  • UIView animation in completion block starts with displacement
  • List all Apps and Track Internet Usage
  • Handling Back To Back HTTP Posts SWIFT 4.0
  • Azure App Service Push - registration endpoint
  • Select multiple item in a tableView
  • Apartment number / Unit number returned from google places api
  • How to align UICollectionViewCells from left to right?
  • How can I add search option on UIPickerview in ios?
  • Scenekit - physicsWorld setup to prevent kinematic nodes to intersect
  • Carthage Build Failed
  • swift 3, ios 10 - push notification firebase is not received
  • App Xcode 8 to Xcode 9 - Prevent Auto Hide Status Bar
  • How to pop back to a TableViewController?
  • Is UserDefaults thread safe in Swift? How to check it?
  • UISwitch in a table selects multiple cells when switch state on
  • iOS App with no story board (Size classes and Device type limitations)
  • AudioKit issue, mic not sensitive enough
  • send indexpath to Firebase (like button)
  • UIColor saturation brightness values different from the regular saturation luminosity values of a color
  • JSON: Extracting Data Using Alamofire and Swift 3
  • invalid_grant on OAuth2 request when obtaining access_token from SSO in App
  • ABNewPersonViewController using contact framework
  • Design iOS button scalable
  • Subclassing NSLayoutConstraint constant based on screen height
  • Migrate Realm 2.x List of Object to Realm 3.x List of String (or other primary type)
  • Using BLE RSSI value for connect-by-proximity
  • Backgroundcolor of NSTextfield
  • Firebase modifying uid in every view
  • How to rotate orientation?
  • Upload a new version of ios app to app store?
  • UIScrollView do not scroll down to its original position when keyboard disappear
  • What is the most effective way of tracking time/dates in an iOS/Swift application?
  • WatchKit get user's preferred handedness
  • Location permission dialog is shown and immediately disappears
  • Combine these regex expressions
  • How to save an array of HKQuantitySamples (heart rate) to a workout
  • RestKit mapping with parent key as attribute and key contains parenthesis
  • How to add UITextField programmatically to UIScrollView without breaking constraints?
  • How to make a view height grow depending on its child views contents
  • Some users experiencing NSInternalInconsistencyException crash
  • Mark successful siesta response as error
  • Using a modified PDFTron Tools Framework
  • How can I use universal links when I call openURL inside my own app?
  • NSArray of doubles iOS (Objective c)
  • Passing data from embedded PageViewController to parent View Controller
  • Reuse item inside a row when scrolling
  • Realm Relation how to implement
  • error: generic parameter 'T' could not be inferred in swift
  • Adding shadow to UITextView makes text expand out of UITextViewFrame
  • How to change the string in seconds to minutes in Swift3?
  • Search bar is refreshing the index of my table view cell
  • Decodable multiple DateDecodingStrategies
  • The spoiled simulator xcode 9. As a broken TV
  • How to set width of TouchableWithoutFeedback depends on Text in react-native?
  • How to show an UIActivityIndicatorView whitin UITableViewController?
  • UItextfield text in Custom UITableViewCell prints nil when i scroll up in SE
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org