I have the following code in a swift UITableViewController, but i get a "Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES exception at the 2nd line. I didnt change any settings in the interface builder (so Autolayout and size classes are both checked).
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell? {
let cell:TodoItemCell = tableView.dequeueReusableCellWithIdentifier("TodoItemCell", forIndexPath: indexPath) as TodoItemCell
let row = indexPath.row
cell.titleLabel.text = self.todoItems![row].title
self.callback!(row)
// Configure the cell...
return cell
}
What am i doing wrong?
Autoresizing masks is a layout method using a bit mask, or an encoded set of flags, that defines how a view should respond to changes in the superview's bounds. The properties available in a autoresizing mask on a view are: Flexible Top Margin, meaning resizing can change the view's top margin.
An integer bit mask that determines how the receiver resizes itself when its superview's bounds change.
Not sure how much this helps, but I see the same error if I try to place a cell directly in a UIView rather than in a table. This worked fine with Xcode 5 so I suspect it is a bug with XCode6/ios8. In the mean time, debug into that method and look at your tableView. Make sure it actually has an instance of the cell you are trying to retrieve.
Update: Filed a bug report with Apple and I can confirm that this is an ios8 issue. Unfortunately it is still there as of beta-5, hopefully they will have it fixed before the final release.
This is NOT a bug, you simply cannot use a UIView
as cell for table view, you must make sure the top level view in the nib file is a UITableViewCell
.
I had this issue because I changed the Layout
property of the ContentView
in the cell to Inferred (Constraints)
. Switching it back to Autoresizing Mask
fixed the issue.
in IOS 15, if you have this setting set the wrong way, your app will crash
In my case, I was loading a nib file with a UITableViewCell contained in a UIView. After disabling autolayout in the nib file, I haven't got the exception again.
I also ran into this issue and it was due to a UITableViewCell
subclass being used in the view hierarchy outside of a UITableView
as noted in the other answers. In this case I had limited time, so I couldn't move the functionality present in that subclass into a UIView
subclass. The workaround I came up with was to just create a UIView
instance in my view hierarchy where the cell was supposed to be and transplant the view hierarchy of the cell instance into it, and remove the cell itself from the displayed view hierarchy. So long as I kept the views I moved wired to the various properties of the cell instance, everything keeps working fine.
It's a bit hacky, but it will keep things running until the time to refactor is available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With