1

I have a Tab Bar with some view controllers, and one of the controller contains a TableView. My problem is that it appears in black 90% of the time. May be it is linked I think to the constraint, the size, because if I touch the constraint, the size, the frame origin, some times it is not black.

Impossible to avoid the blackscreen, and a tableview well displayed with the good size, at the good position. It is very frustrating because all is working on the other 4 viewcontrollers except that view that contains the tableview.

Storyboard viewcontroller:
StoryBoard options

viewController on simulator with no constraints:
ViewController on simulator without constraints

viewControlelr on simulator with constraints (whatever the change I do, it doesn't display correctly. The buttons disappear, the label too). ViewController with constraints

I tried the solutions in this tickets with no success:

self.definesPresentationContext = true  

Link 1
Link 2
Link 3

(I precise that I am trying to find a solution to this, not adding lots of navigationcontrollers after the tabBar or changing the tab bar method itself)

Any suggestions?

EDIT: Here is all the constraints:
Constraints

ΩlostA
  • 2,501
  • 5
  • 27
  • 63
  • can you show me the constraints for every object in your view? – javier rivarola Jan 13 '20 at 14:21
  • Try `Debug View Hierarchy` – vpoltave Jan 13 '20 at 14:24
  • @javierrivarola Hi, I just add the exhaustive list of constraints in the ticket for this viewcontroller and all objects :) – ΩlostA Jan 13 '20 at 14:25
  • i will suggest you first create a container view for all your objects on the top part, and put them inside of it, use a StackView for handling your labels, and attach the table view top constraint to the bottom of the container view, so if you need to change your top layout you don't mess with the rest of the constraints, that will probably also fix any kind of constraints errors you might have done – javier rivarola Jan 13 '20 at 14:31
  • i see you have multiple constraints from the tableView top to your other objects, you should only have one, to the main top container view – javier rivarola Jan 13 '20 at 14:31
  • Add a height to your ImageAlliance.jpg. Everything collapses because this imageView has no defined height. – Starsky Jan 13 '20 at 14:34
  • @Starsky I tried just to fix the height like to said me, it works, but how can I that image that has the good size for all the iphone (I don't care if the image is not at the good proportion at this point :D) ? It don't know if it solve the problem for now. I touched another view controllers, and this view becomes black again. Strange. – ΩlostA Jan 13 '20 at 14:45
  • Please do what i recommended, it will be much easier to fix the rest of your constraints – javier rivarola Jan 13 '20 at 14:54
  • @ΩlostA you make the imageView either a hardcoded height, or set its aspectRatio in respect to the main view. Also, you can make the imageView's contentMode to "Aspect Fill". – Starsky Jan 13 '20 at 15:57

1 Answers1

1

You should use the navigationController for each view controller of your tab bar because it is a bug in the storyboard that haven't been resolved until today

1/ Put the line self.definesPresentationContext = true in each view of the tabbarviewcontroller

2 / Editor/Embed/NavigationController for each view of the tabBarViewController

3 / Remove "Show Navigation Bar " for each Navigation Controller of all the viewControllers of the TabBarViewController

4 / Instead of

let vc = self.tabBarController!.viewControllers![1] as! YourViewController

Put this line :

        let nc = self.tabBarController!.viewControllers![1] as! UINavigationController
        let vc: YourViewController = nc.viewControllers[0] as! YourViewController

5 / resolve all the constaints issues (in red, and in yellow in the storyboard)

6 / Remove the app before compilation on simulator or device

7 / Before the compilation, do a hard clean (Cmd + option + Shift + k)

8 / optional : in some case, close XCode, and relaunch it

dt dino
  • 1,194
  • 6
  • 19