UIViewController show ambiguous with any subviews inside it - ios

I'm got a problem with a view controller which is holding some subviews. My view controller always shows position ambiguous if I added any other views so it makes my view controller cannot show full screen. I'm using View Debugging of XCode to know that warning error. But if the view controller blank, it's work like the bug never happened. This is so weird and I never see it for 4 years working with iOS. Did anyone know about this issue before and how to fix it?
when I add just one view inside:
And result:
And when I just set background for this viewcontroller

Related

Compiling and running my tvOS project with the new Xcode13+, the tab bar scrolls with the scrollView and I can't access the split view controller

When I compile and run my tvOS project with the new Xcode13+, the tab bar scrolls with the scrollView, and I can't access the split view controller moving the focus.
The issue doesn't happen with Xcode < 13. However, after updating to Monterey, I don't have a choice.
Pre-condition:
Create an app on tvOS with a tab bar controller;
In one of the tab, put a split view controller;
In the collapsed master view controller, put a table view.
Issue 1:
Observe that moving the focus towards the left to open the collapsed master view controller, doesn't work anymore. The master view controller won't be pulled out. The only way to pull it out is to tap the back button (ex menu button).
Issue 2:
Scrolling down on the tableView in the master view controller would also scroll away the tab bar at the top (this was possible only setting the tabBarObservedScrollView before, but now is deprecated and it happens automatically. Even using [self setContentScrollView:nil forEdge:NSDirectionalRectEdgeAll] doesn't help.
Did anyone get the same problem? Do you know why this happens and if it can be solved?
In the meantime, I reported the problem to Apple.
PS. another odd thing is that the Apple documentation for setContentScrollView:forEdge: is empty (as of today).
Update:
Observe how even setting the property to nil, it is still populated:
After deeper investigation, I found that the problem happens only when compiling with Xcode13+ and running on tvOS15+.
For some reason, the property above is automatically populated for ALL UITableViewController.
Replacing the UITableViewController with a UIViewController with a UITableView inside solves the Apple issue.
This is a bug with Apple SDK:
Observe how even setting the property tabBarObservedScrollView to nil, it is still populated:
This happens for ALL UITableViewController.
Replacing the UITableViewController with a UIViewController with a UITableView inside wor the Apple issue.
--
Regarding the swipe left, it's another Apple bug or decision to not allow the focus to move on the master view controller when on a split view controller.

UICollectionViewLayout shouldInvalidateLayout(forBoundsChange:) Method Not Called on Device Rotation if View Controller Is In a UINavigationController

I am facing an issue where the shouldInvalidateLayout(forBoundsChange:) method of a UICollectionViewLayout subclass is not getting called on device rotation, but only when the view controller with the collection view is embedded inside of a UINavigationController. If I remove the root view controller from the navigation controller and show it on its own, this method gets called and my layout is able to then correctly invalidate and update for the new device orientation.
Here's a sample project I created to show the issue. The first tab has just the view controller displayed and you can see by rotating the simulator that shouldInvalidateLayout(forBoundsChange:) is called. The second tab has the same view controller embedded in a navigation controller and on rotation you can see in the console that shouldInvalidateLayout(forBoundsChange:) does not get called. The actual project that I'm seeing this occur in uses a slightly more complex subclass of UICollectionViewLayout, but poses the same issue as seen here with a simple subclass of UICollectionViewFlowLayout. Since our project's layout requires slightly more heavy computations, we rely on shouldInvalidateLayout(forBoundsChange:) returning true and invalidating the layout before recalculating all of the layout attributes. Since this is never called, it causes our cells to remain the same width after rotation instead of updating for the new width.
This behavior is very strange and seems undocumented to me from what I have seen. Does anyone have any insights as to why the navigation controller causes this change and how to modify it so that shouldInvalidate is called on rotation?
Some things I've tried (non-exhaustive list):
Various combinations of hiding and showing the navigation bar/toolbar to see if they have any effect on the bounds of the view on rotation).
Verifying that the bounds of the collection view change on rotation. They do, and you can see the updated bounds when debugging the view hierarchy in Xcode.
Creating the interface entirely programmatically and removing the storyboard. The issue still persists.
Verifying that this issue occurs on different device types. I've tested this on both iPhones with notch/home indicator safe area insets and those without and see the same issue.
Using a different collection view layout. The issue is present for both UICollectionViewFlowLayout and a custom UICollectionViewLayout subclass.
Some similar issues I've come across/read (again, a non-exhaustive list since I've been at this so long):
https://gist.github.com/NeilsUltimateLab/21d551126f0f03b11a0154a681a48e71
https://www.reddit.com/r/iOSProgramming/comments/bd0yh6/what_are_all_the_conditions_that_trigger/
How to properly rotate viewcontrollers in UINavigationController?
https://github.com/radianttap/Fields/issues/3
Thanks for any insights in advance!

Why doesn't input toolbar show when jsqmessages placed in container viewcontroller?

I'm following the SwiftExample from JSQMessagesViewController but attempting to place the ChatViewController into a container view controller. It works as expected except that the text input toolbar does not show at the bottom.
I have experimented with sizing and looking at the hierarchy debug view to see if the input toolbar may be hidden offscreen, but it does not appear to exist. The toolbar is part of the JSQMessagesViewController xib file. Why would it not show?
UPDATE:
I see that jsq_configureMessagesViewController explicitly removes the inputToolbar from the view. If I comment out that line as an experiment I get the toolbar to appear, however it then fails with an error regarding having the wrong parent in the view hierarchy.
So obviously there are things I do not yet understand about input views and the view hierarchy. This thread seems related:
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',
and for what it's worth here is my storyboard showing the container:
Storyboard diagram
The problem seems to be unique to the current development branch. Reverting to an earlier release seems to work.

How to add view in top of view hierarchy in Swift?

I have been using this:
UIApplication.sharedApplication().keyWindow?.rootViewController!.view.addSubview(self.customView)
To add a modal view over all the views in the view hierarchy in app.
But this is giving me problem. It adds subview as expected sometimes but sometimes it doesn't' work.
In what case this wont work and what's the best way to add modal view in view hierarchy like UIAlertView.
Depending on what's happening, there can be more than one UIWindow at a time - for example, if a system alert shows up, you will have two separate windows (one for your view controller, one for the alert itself).
A similar example can be made for the system keyboard. If the keyboard has focus, that will be your keyWindow.
A way of making sure you are adding the subview on top of all windows, could be: UIApplication.sharedApplication().windows.last?.addSubview(yourSubView).
I've also seen people using the application delegate, with: UIApplication.sharedApplication().delegate?.window.

Whose View is not on hierarchy

I am getting this error from swift and I am unsure why there is only 1 view controller that actually has this occurring the error is whose view in not on the hierarchy. My question is why would this occur for one of the view controllers presented from this primary viewcontroller button but not the other view controller linked from this primaryview controller? Is there something that could cause this to occur specifically. I am trying to present this modally and it is being called programmatically so that I can pass data objects.
For me it just seems very strange that this would occur for one viewcontroller presented from this viewcontroller but not the other. The only thing I did which I didn't think would effect this was duplicating the primary viewcontroller but again why would one work but not the other? The problem is specifically happening with iOS.
Should have checked the buttons to make sure they were linked correctly. I realized after reading a few of the same questions that I should check the button selectors under the view controller references tab to see what was linked to what. I had 2 actions doing 2 different things for 1 button by accident I must have miss clicked the control drag function.

Resources