iOS Crash: "A view can only be associated with at most one view controller at a time"

15 hours ago 1
ARTICLE AD BOX

I created a ViewController with a .xib file. In the XIB, I had both File's Owner and a ViewController object set to the same class. This caused iOS to associate the same view with two different ViewController instances — resulting in the crash.

Fix:

Open your .xib file

In the document outline (left side panel), you will see both File's Owner and a ViewController object with the same class assigned

Delete the ViewController object from the XIB — keep only File's Owner

Drag the View and place it just below First Responder in the document outline

Now select File's Owner, open Connections Inspector, and connect the view outlet to your main View

That's it — the crash was gone.

Why this works:

When you create a ViewController with XIB, File's Owner is already responsible for managing the view. Having a separate ViewController object with the same class creates a conflict because iOS cannot associate one view with two controllers at the same time.

Read Entire Article