Why am I getting a quot;Auto Layout still required after executing -layoutSubviewsquot; error every time my app launches now?(为什么我得到一个“执行 -layoutSubviews 后仍然需要自动布局?每次我的应用程序现在启动时都会出错?)
问题描述
由于我添加了以下代码,每次我的应用打开此 UITableViewController 时它都会崩溃:
Since I added the following code, every time my app opens this UITableViewController it crashes:
self.noArticlesView = [[UIView alloc] init];
self.noArticlesView.translatesAutoresizingMaskIntoConstraints = NO;
self.noArticlesView.backgroundColor = [UIColor colorWithRed:0.961 green:0.961 blue:0.961 alpha:1];
[self.view addSubview:self.noArticlesView];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.noArticlesView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.noArticlesView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.noArticlesView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.noArticlesView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0]];
它给了我这个错误:
* 由于未捕获的异常NSInternalInconsistencyException"而终止应用程序,原因:执行 -layoutSubviews 后仍需要自动布局.UITableView的-layoutSubviews的实现需要调用super.'
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UITableView's implementation of -layoutSubviews needs to call super.'
我到底做错了什么?当有 0 行时,我在 tableView:numberOfRowsInSection: 中调用该代码.
What on earth am I doing wrong? I call that code in tableView:numberOfRowsInSection: when there's 0 rows.
推荐答案
我正在继承 UIScrollView 并在 iOS 7(但不是 8)上收到相同的错误消息.
I was subclassing UIScrollView and received the same error message on iOS 7 (but not 8).
我以类似于以下方式覆盖 layoutSubviews:
I was overriding layoutSubviews in a manner similar to the following:
- (void)layoutSubviews {
[super layoutSubviews];
// code to scroll the view
}
我解决了这个问题,把对 super 的 layoutSubviews 的调用移到方法中的最后一件事:
I resolved the issue by moving the call to super's layoutSubviews to be the last thing in the method:
- (void)layoutSubviews {
// code to scroll the view
[super layoutSubviews];
}
这篇关于为什么我得到一个“执行 -layoutSubviews 后仍然需要自动布局"?每次我的应用程序现在启动时都会出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么我得到一个“执行 -layoutSubviews 后仍然需要自动布局"?每次我的应用程序现在启动时都会出错?
基础教程推荐
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
