1

im trying subclass uitableviewcell.

at first i was using uitableviewcontroller with no problem and everything works

well. the problem was i couldnt insert static view top of uitableview. so i

started to use uiview + uitableview. i set delegate and datasource to my uitable

but when i tried to compile my solution i get this error :

2015-03-04 15:00:53.087 News[7410:750801] *** Assertion failure in -[SubcategoryTableViewCell _setHostsLayoutEngine:], /SourceCache/UIKit/UIKit-3318.16.14/NSLayoutConstraint_UIKitAdditions.m:2760
2015-03-04 15:00:58.132 News[7410:750801] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES.'
*** First throw call stack:
(0x182b59e48 0x19324c0e4 0x182b59d08 0x1839dd554 0x1873d6088 0x1873df4f0 0x1876f3c60 0x18771475c 0x1877eccc8 0x1877ecc68 0x1877ec984 0x1875c96f8 0x187832244 0x1877eccc8 0x1877ecc68 0x1877ec984 0x1875c96f8 0x1876f3c44 0x18771475c 0x1877eccc8 0x1877ec984 0x187714264 0x1877eccc8 0x1877ecc68 0x1877ec984 0x1877136ec 0x187446cac 0x1000292e8 0x187421854 0x1873e369c 0x1873e58f0 0x1873e582c 0x1873e5178 0x10003ad30 0x100344e30 0x100344df0 0x10034975c 0x182b116a0 0x182b0f748 0x182a3d1f4 0x18bbd35a4 0x18736e784 0x100029bf4 0x1938baa08)
libc++abi.dylib: terminating with uncaught exception of type NSException

on this part of code :

- (SubcategoryTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseIdentifier = @"PlaceholderCell2";
    SubcategoryTableViewCell * sctvCell = [self.tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (sctvCell == nil) {
        sctvCell= [[SubcategoryTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]; 
    }

in storyboard i set my uitableviewcell to my cell custome class. and it works

perfectly with uitableview controller.

this is my class and subclass code :

weird behavior on dynamic uitableviewcell height

Community
  • 1
  • 1
Ahad Porkar
  • 1,666
  • 2
  • 33
  • 68
  • This seems to be a bug with xCode 6. There is a related discussion [here](http://stackoverflow.com/questions/24217195/why-do-i-get-must-translate-autoresizing-mask-into-constraints-to-have-sethost) – spassas Mar 06 '15 at 15:04
  • yeah i guess so. but is there any work around !? – Ahad Porkar Mar 06 '15 at 15:14
  • Disabling autolayout in the nib file of the tableview cell could be a solution (?) – spassas Mar 06 '15 at 15:15
  • im using storyboard for solution. also the uitableviewcell subclass is referring to same cell in the storyboard without any extra nib file. – Ahad Porkar Mar 06 '15 at 15:18

2 Answers2

2

well. the problem was i couldnt insert static view top of uitableview.

There are several workarounds for this.

  1. Put the static view on the window ([self.tableView.window addSubview:staticView]). You will need to manage the removal of the static view before the table view controller disappears.

  2. Have an outer view controller which has the static view. The outer view controller has your table view controller in a container view.


Back to your current issue. When you swapped the table view controller for a regular view controller, did you rebuild your storyboard? Simply swapping the type will cause errors.

Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117
0

I had faced a similar problem regarding layout constraints.Modify your UITableViewCell class constructor like below.

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
    {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self) {
            self.translatesAutoresizingMaskIntoConstraints = NO;
        // Your initializations here
    }
    return self;
    }
AppleDelegate
  • 4,269
  • 1
  • 20
  • 27