0

I was trying to add a subview to tableview using autolayout, but I get this Assertion failure when I do so.

" * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UITableView's implementation of -layoutSubviews needs to call super.'"

My code

UIView *view = [[UIView alloc] init];
[view setBackgroundColor:[UIColor redColor]];
[parentView addSubview:view];

[view setTranslatesAutoresizingMaskIntoConstraints:NO];

    NSLayoutConstraint *c1 = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:parentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0];
    NSLayoutConstraint *c2 = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:parentView attribute:NSLayoutAttributeLeft multiplier:0.0 constant:10.0];
    NSLayoutConstraint *c3 = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:parentView attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0.0];
    NSLayoutConstraint *c4 = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:parentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:50.0];

    [parentView addConstraint:c1];
    [parentView addConstraint:c3];
    [parentView addConstraint:c2];
    [parentView addConstraint:c1];

but if I set frame to the view without any autolayout constraint, it works fine. I couldn't figure out what I am missing.

Sunny Shah
  • 12,990
  • 9
  • 50
  • 86
Friendtam
  • 311
  • 4
  • 11
  • Did you call `[super layoutSubviews]` from within your `-layoutSubviews` implementation? – i_am_jorf Sep 03 '14 at 16:48
  • possible duplicate of [Why am I getting a "Auto Layout still required after executing -layoutSubviews" error every time my app launches now?](http://stackoverflow.com/questions/19837097/why-am-i-getting-a-auto-layout-still-required-after-executing-layoutsubviews) – The dude Sep 05 '14 at 09:13

0 Answers0