Finding Missing Constraint - xcode

When I build my app Xcode gives me five warnings relating to missing constraints. But clicking on them in the Navigation Panel only takes me to a ViewController in the Storyboard and doesn't highlight which view has the problem.
In addition, as shown above, the Storyboard doesn't contain any yellow triangles at all, so I'm at a loss as to how to find which view is missing the constraints.
The errors don't appear when I run the app, so how to I try to trap these errors in the build?
(Xcode 14.2)

Xcode and Storyboards have lots of bugs...
One that you're encountering is the failure to show error/warning indicators.
This is how it should look:
Clicking that indicator will show you the specific warnings - and hovering over one shows you the view in question:
However, those indictors and descriptions are sometimes missing. Seems to happen most often when you have multiple view controllers in a single Storyboard.
You could copy each controller to a new Storyboard to see if the information shows up - but, based on my experience, it's hit-or-miss.
In your specific case, warnings such as:
Leading constraint is missing, which may cause overlapping with other views.
can be safely ignored... provided you know and understand the layout you've designed.

Related

Struggles with side-by-side NSTableView and Contraint layout, part 2

Previously, I asked about using constraint layout to put two NSTableView side-by-side. Side-by-side NSTableView using StackView and Constraints Thanks to Willeke's help, I was able to achieve this using only constraints, and no StackView.
The recommendation there was:
[...] Xcode is buggy. Avoid resizing the window and/or solve layout issues by updating the frames (in Xcode 9: menu Editor -> Resolve Layout Issues -> Update Frames).
I'm still having trouble with that, unfortunately. When I run my app, it now looks fine. However, in Interface Builder, clicking "Update Frames" actually makes the layout progressively worse, such that I have to Git reset to get back to a reasonable layout. I'm worried that later, when I actually need to update my view, I will be in trouble because I am unable to touch it without breaking it.
I've tried to illustrate the issue:
I'm unsure if it's helpful, but here is my list of constraints:
What could be wrong here? Have I forgotten some obvious constraint?

Weird NSOutlineView crash

I'm experiencing weird crash in NSOutlineView: when i click "collapse" button, app crashes immediately and even "exception breakpoint" doesn't help to see where the problem is.
I've tried to run app without debugger, and reproduced the problem. Once app crashed, i've got OSX crash window and was able to extract crash message from there:
The window has been marked as needing another Update Constraints in Window pass, but it has already had more Update Constraints in Window passes than there are views in the window
there also call stack, but it won't help since crash happening inside libsystem_c.dylib, so i'm not posting it here.
It seems there is something wrong going with auto layout. Absolutely have no idea about next steps. Please give me an advice!
Also, one more thing, that began only after update to OSX Mojave.
After hours of debugging and testing, i noticed that that message is caused by "infinite layout loop".
Different code, related to outline view was causing NSSplitView to layout. And delegate method - (CGFloat) splitView:(NSSplitView*)sender constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex has been called about 200 times prior to crash.
It's hard to catch this bcs it's not actually infinite recursion, so just debugger doesnt help a lot.
I just added simple code that helped me to identify the issue:
static int a = 0;
NSLog(#"Layout: %d", a++);
Hope my experience will help somebody else!
For anyone who is having the problem in Xcode 14 and macOS using SwiftUI:
I just had the same crash by hiding a view with an animation. My main view contains two views, one view contained an empty ScrollView, which didn't cause a problem by itself, but by changing it's size it crashed. Just adding a basic Text within the ScrollView solved my problem and the app doesn't crash anymore.
I updated my build to IOS 14 and Mac OS 20.15.6 and the error went away.
try turning off 'Use Auto Layout' checkbox in nib (in File Inspector tab).
May have to disable it for each and every view.
Also, unrelated, but Mojave forces you to use Core Animation.
Most of my nibs have 'set wants layer' turned off.
However, in one of my nibs I had a stray setWantsLayer checkbox checked.
when I unchecked it, the view (NSSearchField) drew properly

Constraints keep going haywire every time I reopen an XCode project

Every time I close and reopen XCode 6 beta 6, my previously-happy constraints are messed up and I have to click on the yellow dot to get to the "Misplaced Views" thingy, then click on each yellow triangle, choose Update Frame, and click Fix Misplacement to correct the problem. Is this a bug in the beta or have I done something wrong, perhaps? Constraints in XCode (to me, at least) are horrible things to tame at the best of times, so maybe it's not a bug?
Once fixed, and XCode neither complains about nor renders the widgets badly, it's fine. But as soon as I close then reopen the project, they're messed up again.
I have experienced the same thing on a project I'm working on. What I've observed is a circular connection among the views in the storyboard in question, so that it's possible to segue around and around a particular path or paths. The views are all embedded in a TabBarController, and each tab has its own NavigationController.
So for instance:
Activity View (programmatically selected tab), segue to ...
Detail View, segue to ...
Profile View (programmatically selected tab), segue to ...
Item View, segue to ...
Detail view
... and so on
This seems to introduce random screwups to the views.
What I have not yet done is test this by removing the circular segue paths. I'm not sure I ever will, since the circular segue paths are part of the functionality of the app. But I'm pretty sure that was about where this weird behavior got introduced. I'll be interested to hear whether the same is true of your project.

Strange behavior with accessory views on NSSavePanel and NSOpenPanel in sandboxed app

I have a problem with accessory views on NSSavePanel and NSOpenPanel.
Sometimes, (very often) when I open one of these panels the accessory view does not work (the view is shown but controls seem disabled).
I'm using this code to show the panel:
[openPanel beginSheetModalForWindow:appWindow completionHandler:openPanelHandler];
This only happens when app-sandbox is enabled.
After much testing I found out that what was happening was that the view was being misplaced (not attached to the panel).
When I open Mission Control and move the mouse pointer over the app windows I noticed that an "invisible" window hilighted and when select it I can take control over the accessory view (all controls work) but it appears detached from the open or save panel as shown on the screenshot.
I tried to create a new app just to test this behavior but was not able to reproduce it, so I suppose that has something to do with my app.
Any hint of what I may be doing wrong?
I don't want to code everything from scratch just to solve this issue.
Edit
Just a side note, when I close the window, just before the window close the accessory view flashes with the correct values for the controls. It appears that the application does not add the view in time for showing the panel.
Update 1
I subclassed the view that is used as accessory view and noticed that the
- (void)viewWillMoveToSuperview:(NSView *)newSuperview
is called, but
- (void)viewDidMoveToSuperview
never gets called even when the view is shown correctly, is this the normal behavior?
Update 2
I confirmed that - (void)viewDidMoveToSuperview should be called, on the test app both methods are called.
I also noticed a slight difference between my app and the test app. On my app the panel just slides down but on the test app the panel appears to "flip down" (don't know exactly how describe). The way the panel appears is irrelevant to me, I just noticed that it is not shown the same way.
After trying many things I concluded that the problem had to do with ARC (Automatic Reference Count) settings for the project.
In my case I had enabled ARC on target but not on project, after enabling ARC on project (and dealing with resulting errors and warnings) everything works perfectly now.

Interface-Builder outlets causing odd display behaviour

I've been working today on adding a sheet to the main window of my application. After having trouble seperating the two (main view/controller and sheet view/controller), I've gone with just having both views in the same xib and both controlled by the main controller. Now that it appears when the beginSheet method is called, I've designed the form, and hooked it up to the IBOutlets/Actions on my controller.
This is where the problem is. With no bindings between the forms objects and the controller, it displays perfectly. But when I connect buttons to IBActions, and text fields/imageviews to IBOutlets I encounter some weird display problems. I'm talking buttons not displaying (but the actions being executed when clicking where they should be), borders of NSBox's not showing and textfields not taking any typed text and displaying (still blank) further off the viewable area of the panel.
I discovered that I could rectify this by resizing the panel a little, but that's not usable. I did get it working fine with 3 textfields and 3 buttons and just close/minimize enabled (not that they actually seem to do anything to a sheet), but now I've hooked an imageview up to the controller and the one of the buttons isn't displaying again.
Is this something to do with the number of outlets/actions I'm using (The actual main window doesn't actually have any extra ones) or is it IB being buggy or me doing something very wrong?
My first suspicion would be that there is an exception being thrown somewhere during drawing the sheet. In my experience, that's usually the case when you get half-drawn controls like you're describing. Check the debugger console in Xcode to see if any error messages are being printed out there. You can also add a breakpoint on objc_exception_throw to have the debugger stop when an exception is thrown, that might shed further light on where exactly the problem is coming from.
This issue went away when I reconstructed the sheet from scratch. I do not know what caused the issue, but if anyone has a similar problem I would suggest trying to reconstruct it in a new sheet.

Resources