Search code examples
iospresentviewcontroller

Present View Controller and Add Child View Controller Cause App Freeze


I have AViewController. Inside A, I have a MapViewController instance. MapViewController is A's Child View Controller.

Now when a button inside A got TouchUpInside, I init a BViewController. and present B.

When init BViewController I pass in the MapViewController to B and stored inside B as an unowned variable.

I need to display the same map for both A and B. Inside B's viewDidLoad, I add MapViewController as Child View Controller for B.

The app freezes when I press the button. No exception, No crash, No error log.

Anyone have any ideas why it happens?


My Attempts:

  1. I tried to use a navigation controller and use pushViewController methods, same result, app freezes
  2. I tried to add MapViewController as child inside B at ViewWillAppear, same result, app freezes
  3. I tried to add MapViewController as child inside B at ViewDidAppear, no more freeze, but map is not there at all.
  4. Instead of present B I tried to add B as childViewController of A, same result, app freezes
  5. I checked all the instructions on running on main threads.
  6. I tried to remove mapViewController as child in A before present B, same result, app freezes.
  7. I tried to add mapViewController as child in completion block when present B, same result, app freezes

Solution

  • This may be a better structure to take. When you switch from A content to B content, you can move / size the elements all you want... And since they will be separate subviews of your "main" view, they can overlap if your interface would benefit from that layout:

    enter image description here