1

I develop my app in XCode 5, and I create my view controller(UIViewController instance) in storyboard. And I add a UITableView as its' subview, after that I create a custom tableview cell.

Then, in the view controller's .m file, I create a UIActivityIndicatorView instance and add it to the cell as it subview. The UIActivityIndicatorView lazy load method like below:

-(UIActivityIndicatorView *)loadingIndicator
{

    if (!_loadingIndicator) {
     _loadingIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

    [self addSubview:_loadingIndicator];

    _loadingIndicator.translatesAutoresizingMaskIntoConstraints = NO;

    NSLayoutConstraint *centerX = [NSLayoutConstraint constraintWithItem:_loadingIndicator attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.questionBodyWebView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0f];

    NSLayoutConstraint *centerY = [NSLayoutConstraint constraintWithItem:_loadingIndicator attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.questionBodyWebView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0];

    [self addConstraints:@[centerX, centerY]];  
    }
    return _loadingIndicator;
}

It will work fine in my ipad mini(iOS7), but when I run it in simulator ipad(iOS 6.1), it will crash, and the console output like this:

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

Can some one tell me why? Wait for your help, thanks!

chancyWu
  • 14,073
  • 11
  • 62
  • 81
billwang1990
  • 627
  • 2
  • 6
  • 16
  • possible duplicate of ["Auto Layout still required after executing -layoutSubviews" with UITableViewCell subclass](http://stackoverflow.com/questions/12610783/auto-layout-still-required-after-executing-layoutsubviews-with-uitableviewcel) – kovpas Jan 03 '14 at 09:52
  • It seems a good way use swizzling to fix the error, but Apple will allowed this? – billwang1990 Jan 04 '14 at 02:23
  • Yep, swizzling is widely used (although, personally, I'm not a big fan of it). – kovpas Jan 04 '14 at 13:04

0 Answers0