首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么每次启动我的应用程序时都会收到“执行-layoutSubviews后仍然需要自动布局”的错误?

为什么每次启动我的应用程序时都会收到“执行-layoutSubviews后仍然需要自动布局”的错误?
EN

Stack Overflow用户
提问于 2013-11-07 21:22:07
回答 9查看 14.8K关注 0票数 18

因为我添加了以下代码,所以我的应用程序每次打开这个UITableViewController时都会崩溃:

 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.‘

我到底做错了什么?当有0行时,我在tableView:numberOfRowsInSection:中调用该代码。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19837097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档