11

I am updating a project to iOS 8 and am running into this issue with one of my UITableViewCell implementations. Currently on Simulator and not a device and it is set to "iPhone 6".

*** Assertion failure in -[UITableViewCell _setHostsLayoutEngine:], /SourceCache/UIKit_Sim/UIKit-3318/NSLayoutConstraint_UIKitAdditions.m:2754
2014-09-15 10:43:52.890 BasketballStatTracker[10662:304085] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES.'

The odd part is that I am using this Custom UITableViewCell subclass in all my other UITableViews and it is working well without any asserts.

Here is the cellForRowAtIndexPath: implementation.

MyTableCell *cell =(MyTableCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    cell =[[MyTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

Here is the stack trace

0   CoreFoundation                      0x000000010844e3f5 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x00000001080e7bb7 objc_exception_throw + 45
2   CoreFoundation                      0x000000010844e25a +[NSException raise:format:arguments:] + 106
3   Foundation                          0x0000000107ac228f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4   UIKit                               0x0000000106de2e1c -[UIView(AdditionalLayoutSupport) _setHostsLayoutEngine:] + 188
5   UIKit                               0x00000001069e7d92 -[UITableViewCell _setupTableViewCellCommon] + 333
6   UIKit                               0x00000001069e84d7 -[UITableViewCell initWithCoder:] + 109
7   UIKit                               0x0000000106b8a996 UINibDecoderDecodeObjectForValue + 705

Any ideas?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Caleb
  • 631
  • 6
  • 15

1 Answers1

11

I located an errant UITableViewCell that was placed within the view hierarchy of the troubled .xib. Removing it fixed the problem.

Caleb
  • 631
  • 6
  • 15
  • If I remember correctly I had a UITableViewCell UI element that I was unaware of within my .xib. Are you using storyboards or xibs? – Caleb Nov 18 '14 at 23:54
  • 1
    I am using storyboard – Puvanarajan Nov 19 '14 at 05:00
  • 1
    So what's the answer? I'm still stuck with this stupid error. Any leads? – Kaveh Vejdani Feb 10 '15 at 01:12
  • Kaveh Vejdani what is your UI structure? Are you using autolayout? Do you have a thread you can link? If so I will take a look and see if it is a similar issue to what I was experiencing. – Caleb Feb 11 '15 at 05:28
  • Unchecking Auto Layout is fixing the error for me... but the problem is that I'd really like to use Auto Layout :/ The only page for me that has an issue is one where I use a table view cell in a UIView, and that may be causing an issue (as described here: http://stackoverflow.com/questions/24217195/why-do-i-get-must-translate-autoresizing-mask-into-constraints-to-have-sethost) – deebs Feb 11 '15 at 19:23
  • That may be the problem. I always give my UITableViewCells their own xib. I also usually register the cell with the table in code. I would try moving to its own xib and see if that helps your situation. – Caleb Feb 12 '15 at 20:01
  • Caleb, yes I am using an autolayout. Sorry I don't have a link. Is there a way to turn off autoresizingmask at runtime? Will that solve this weird problem? – Kaveh Vejdani Feb 13 '15 at 22:08
  • Thank you Deebs for the other link. Good to know this is an Xcode bug. First major bug for me in the past 3.5 years. Impatiently awaiting the fix. Will temporarily assign my UITableView frame at runtime as a quick and dirty fix. – Kaveh Vejdani Feb 13 '15 at 22:16
  • you've just saved my day! exactly same thing, pasted a cell into view instead of table view. – Can Poyrazoğlu Mar 11 '15 at 13:14
  • This helped me out too! For some reason, a `UILabel` within my cell had its class renamed to that of another `UITableViewCell` subclass. – bodacious Jul 08 '16 at 18:15