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

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.

Related

Where did tabbed controller views go in storyboard?

Forgive but I haven't coded in about a year or two, so I haven't been following the latest update in Xcode.
Anyways, I decided to go back and brush up on some skills and I noticed right off the bat that a lot has changed.
I created a new project using the tabbed view controller set up, usually it shows in storyboard immediately upon creating the project. Now there is nothing there. Where did it go and how do I bring it back?
I attached a screenshot so you can see the simulator running the tabbed apps but not showing in storyboard.
enter image description here
You opened the LaunchScreen.storyboard. This layout appears on the screen for a few moments while the app is launching.
https://developer.apple.com/documentation/uikit/app_and_environment/responding_to_the_launch_of_your_app
https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/launch-screen
The storyboard that you are looking for is Main.storyboard
Notice, that there is no Main.storyboard if you start with SwiftUI
There are no specialized app templates any more. But there is still a tab view controller object in the storyboard editor's library, so just drag it into the canvas and use it. It gives you same two-child tab view controller as before.

How to convert manual view controller to storyboard as a launch screen

New iOS requirements need Apps for iPhone or iPad must be built with the iOS 13 SDK or later and use an Xcode storyboard to provide the app’s launch screen.
But my project is very old and has never used Storyboards. All UI elements are created dynamically using ViewControllers.
I managed to create a storyboard file and set it as a launcher but it has no scenes and I do not know how to proceed. I would like to:
Create a scene where I place only the original launch image inside (hoping that apple still accepts this branding)
If it is possible to just connect my main ViewController with the scene (if that works with dynamical ViewControllers)
If nothing helps than I would need to create a simple scene which has just a bottom bar like my ViewController
I had this exact issue, here's what I did:
Create LaunchScreen.storyboard and set to use it as launch screen
Using the + button in the top-right (this was not an obvious step), add a View Controller into the storyboard
Untick "Use Safe Area Layout Guides" on the right panel if you're getting that error
Tick "Is Initial View Controller"
Then clean and run, for me it just worked. I did have trouble seeing it update though, as discussed here: Launch Screen storyboard not displaying image

View debugging - UITransitionViews - Xcode

I have some menus in my app wich are all presented modally. In my tests I noticed that the more often I switch between menus the more UITransitionViews are show in the View Debugging Window in Xcode when i capture the View Hierarchy. Is this a normal behavior are am I missing something here. Do I need to dismiss ViewControllers somehow?
I attached a screenshot for better understanding.
You do, I had the same issue and the app memory usage was going up the more I switched between views (views were not dismissed).
You should use delegate where the child view controller can call so the parent view controller can dimiss children properly.

Inactive Controls on ViewController despite working referencing outlets

I was wondering if anyone else has seen this. I would include a screen shot but it would be unilluminating, showing all the referencing outlets and event handlers hooked up exactly as they should be, the same thing that was working perfectly before I made some changes. I had a very simple UIView with some text and a single control which I edited to have more controls, and after building none of them worked. The IBOutlet variables all worked, I was able to set text and control states on viewWillLoad, but all control were inactive. They were enabled, allowing user interaction, I even tried setting their enabled properties in code. Dead.
Finally I created a new view, copied and pasted the subviews into it, hooked up the event handlers and referencing outlets, and it worked right away.
Does anyone have any insights to share on this? I tried cleaning the project, rebooting the machine, the whole gamut. OK, "the nib must have been corrupt," but why?
Thanks for any insights.

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