9 Replies
      Latest reply on Oct 30, 2019 8:42 PM by renrawrd
      neal1 Level 1 Level 1 (10 points)

        I'm adding one UIBarButtonItem with a custom view. The custom view uses autolayout to layout its inner components. Is this supported in iOS 13?  This issue does not happen when the same code is run against an iOS 12 device. Adding just one UIBarButtonItem which has a custom view causes this to happen. None of the UIViews listed in the conflict  below are  mine (e.g: _UIToolbarContentView) and they're clearly private UIView classes.

        I'm not even sure how to debug this issue. I've set the UIToolbar's translatesAutoresizingMaskIntoConstraints to NO, but this issue still happens.

        Setting a breakpoint on UIViewAlertForUnsatisfiableConstraints doesn't help because the stack trace  doesn't give any valuable clues as it's all iOS private classes


        Any suggestions?





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

          (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)


            "<NSAutoresizingMaskLayoutConstraint:0x2815ebe30 h=--& v=--& _UIToolbarContentView:0x100d6f8e0.width == 0   (active)>",

            "<NSLayoutConstraint:0x2815ea120 H:|-(0)-[_UIButtonBarStackView:0x100d31080]   (active, names: '|':_UIToolbarContentView:0x100d6f8e0 )>",

            "<NSLayoutConstraint:0x2815ea170 _UIButtonBarStackView:0x100d31080.trailing == _UIToolbarContentView:0x100d6f8e0.trailing - 16   (active)>"



        Will attempt to recover by breaking constraint

        <NSLayoutConstraint:0x2815ea170 _UIButtonBarStackView:0x100d31080.trailing == _UIToolbarContentView:0x100d6f8e0.trailing - 16   (active)>


        Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.

        • Re: UIToolbar issue in iOS 13
          neal1 Level 1 Level 1 (10 points)

          I solved this by not using a UIToolbar. UIStackView was all that I really needed.

            • Re: UIToolbar issue in iOS 13
              mario25 Level 1 Level 1 (0 points)

              I am also troubled by this problem.


              I heard that you used UIStackView. Can you put UIBarButtonItem in UIStackView?


              The UIBarButtonItem reference states that the button is specialized for the placement of UIToolBar and UITabBar.




              The following code I tried didn't work.


              Please give us advice on what kind of code you have written.


                // note
                UIBarButtonItem *noteButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemCompose target:self action:@selector(noteViewAction)];
                // camera
                UIBarButtonItem *cameraButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemCamera target:self action:@selector(cameraViewAction)];
                // stackView
                UIStackView *stackview;
                stackview = [[UIStackView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 300.0f, 44.0f)];
                stackview.axis = UILayoutConstraintAxisHorizontal;
                stackview.alignment = UIStackViewAlignmentFill;
                stackview.distribution = UIStackViewDistributionFill;
                stackview.spacing = 20;
                [stackview addArrangedSubview: noteButton.customView];
                [stackview addArrangedSubview: cameraButton.customView];
                UIBarButtonItem *stackViewBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:stackview];
                self.navigationItem.leftBarButtonItem = stackViewBarButtonItem;
                • Re: UIToolbar issue in iOS 13
                  neal1 Level 1 Level 1 (10 points)

                  >I heard that you used UIStackView. Can you put UIBarButtonItem in UIStackView?


                  Hi Mario25,

                  You can't put a UIBarButtonItem in a UIStackView, only UIViews or UIControls, but in my case that was fine, because all of our UIBarButtonItems used real UIButtons and UIControls as custom views. So after migrating to a  UIStackview we saved work because we didn't have to create UIBarButtonItem wrappers. Your use case is different in that you still use UIBarButtonItems.

                  • Re: UIToolbar issue in iOS 13
                    4marcus Level 1 Level 1 (0 points)

                    Hi Mario25,


                    I was still stuck at this as well. Did you find anything in regards getting rid of the Constraints problem?

                    My code is still objective-c:


                    I did change the

                    [[UIToolbar alloc] initWithFrame:CGRectZero];



                    [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];


                    while loading the view. This "fixed" the issue for me




                      • Re: UIToolbar issue in iOS 13
                        SkyGanfor Level 1 Level 1 (0 points)

                        This also fixed the issue for me. I was only having this issue on ios 13. Not sure why this is happening.

                        • Re: UIToolbar issue in iOS 13
                          danramtekeconsultinginc Level 1 Level 1 (0 points)

                          This fixed it for me also. Thanks for posting.

                          • Re: UIToolbar issue in iOS 13
                            Leemur Level 1 Level 1 (0 points)

                            Adding the frame size also fixed the problem for me (Using swift). But I still don't know why...


                            Here is my code for example, adding a tool bar for an inputView.  I use a pickerView inside an inputView to choose a country for a textField. Please ask UX guy why I can't use a picker view directly... The textField was created in the storyboard and fixed with autolayout constraints:


                                //MARK:- ConfigurarPickerView
                                //Add the inputView for the textField
                                func configurarPickerView() {
                                    paisPicker = UIPickerView()
                                    paisPicker?.delegate = self
                                    paisTextField.inputView = paisPicker
                                //MARK:- ConfigurarPickerToolBar
                                //Add done & cancel buttons to the inputView toolBar
                                func configurarPickerToolBar(){
                                 //If I don't set the frame size I'll get the LayoutConstraints warning. So I use 100x100 for no reason.
                                    paisPickerToolBar = UIToolbar(frame: CGRect(x: 0,
                                                                                y: 0,
                                                                                width: 100,
                                                                                height: 100))
                                    paisPickerToolBar?.barStyle = UIBarStyle.default
                                    paisPickerToolBar?.isTranslucent = true
                                    paisPickerToolBar?.tintColor = UIColor(named: "ColorNaranja")
                                    let doneButton = UIBarButtonItem(title: "Hecho",
                                                                     style: UIBarButtonItem.Style.done,
                                                                     target: self,
                                                                     action: #selector(donePressed))
                                    let cancelButton = UIBarButtonItem(title: "Cancelar",
                                                                       style: UIBarButtonItem.Style.plain,
                                                                       target: self,
                                                                       action:  #selector(cancelPressed))
                                    let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace,
                                                                      target: nil,
                                                                      action: nil)
                                    paisPickerToolBar?.setItems([cancelButton, spaceButton, doneButton], animated: false)
                                    paisPickerToolBar?.isUserInteractionEnabled = true
                                    paisTextField.inputAccessoryView = paisPickerToolBar
                        • Re: UIToolbar issue in iOS 13
                          renrawrd Level 1 Level 1 (0 points)

                          Just to clarify, to get it to work in IOS 13 we can no longer use the UINavigationItem.leftBarButtonItems property or UINavigationItem.rightBarButtonItems property ?

                          both are UIBarButtonItem objects.


                          i.e. As per the doco

                          "When specifying buttons for a navigation item, you must use UIBarButtonItem objects. If you want to display custom views in the navigation bar, you must wrap those views inside a UIBarButtonItem object before adding them to the navigation item."

                        • Re: UIToolbar issue in iOS 13
                          michaelhenry119 Level 1 Level 1 (0 points)

                          I have noticed this as well.