简体   繁体   中英

UIView title causing constraints problem XIB Xcode

I have one UITabBarController that has 5x child UIViewControllers, each of which is a UINavigationViewController.

For a UIView in any of the UINavigationControllers, If I set the title in viewDidLoad via

self.title=@"TITLE";

Then I get the following unsatisfied constraint error

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)>", "" )

There are no constraints set up in my XIB. This is fairly old (~2013) code so there's probably a deprecation issue somewhere with the autogenerated layouts...?

But if I use

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

There is no the constraints problem, but the TITLE text doesn't appear either, just the empty nav bar.

Im not sure about your issue but if the view has no constraints then there will be no warnings.

Try to add this

translatesAutoresizingMaskIntoConstraints = NO;

to your view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM