Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why do i get "Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES" in xcode 6 beta

Tags:

swift

xcode6

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?

like image 974
Emwee Avatar asked Jun 14 '14 06:06

Emwee


People also ask

What is a view's Autoresizing mask?

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.

What is auto resizing mask in Swift?

An integer bit mask that determines how the receiver resizes itself when its superview's bounds change.


5 Answers

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.

like image 74
pbuchheit Avatar answered Oct 16 '22 20:10

pbuchheit


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.

like image 28
neevek Avatar answered Oct 16 '22 20:10

neevek


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. enter image description here

in IOS 15, if you have this setting set the wrong way, your app will crash

like image 24
otusweb Avatar answered Oct 16 '22 19:10

otusweb


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.

like image 13
Jose Servet Avatar answered Oct 16 '22 20:10

Jose Servet


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.

like image 8
Charles A. Avatar answered Oct 16 '22 21:10

Charles A.