首页 > 解决方案 > UIView 标题导致约束问题 XIB Xcode

问题描述

我有一个具有 5 个子 UIViewController 的 UITabBarController,每个子 UIViewController 都是一个 UINavigationViewController。

对于任何 UINavigationControllers 中的 UIView,如果我通过在 viewDidLoad 中设置标题

self.title=@"TITLE";

然后我得到以下不满足的约束错误

2020-05-28 14:21:23.055778+0100 Datum Connect[6515:10336196] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. 
Try this: 
    (1) look at each constraint and try to figure out which you don't expect; 
    (2) find the code that added the unwanted constraint or constraints and fix it. 

("= UILayoutGuide:0x600001968540'TitleView(0x7fa0a710a390)'.top (active)>", "")

我的 XIB 中没有设置任何约束。这是相当旧的(~2013)代码,所以自动生成的布局可能存在弃用问题......?

但是如果我使用

self.tabBarController.navigationItem.title = @"TITLE";
or
self.navigationController.navigationItem.title=@"TITLE";
or
self.navigationController.title=@"TITLE";

没有约束问题,但 TITLE 文本也没有出现,只是空的导航栏。

标签: iosobjective-cxcode

解决方案


我不确定您的问题,但如果视图没有限制,则不会有警告。

尝试添加这个

translatesAutoresizingMaskIntoConstraints = NO;

在你看来。


推荐阅读