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!