我在XCode 5中开发我的应用程序,并在storyboard中创建我的视图控制器(UIViewController
实例)。我添加了UITableView
作为其子视图,之后我创建了一个自定义的tableview单元格。
然后,在视图控制器的.m文件中,我创建了一个UIActivityIndicatorView
实例,并将其作为子视图添加到单元格中。 UIActivityIndicatorView
延迟加载方法如下所示:
-(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;
}
它可以在我的ipad mini(iOS7)中正常工作,但是当我在模拟器ipad(iOS 6.1)中运行时,它会崩溃,并且控制台输出如下:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UITableView's implementation of -layoutSubviews needs to call super.'
有人可以告诉我为什么吗?等等你的帮助,谢谢!