I have two UIViewController
. One is ViewController, and another is GameplayViewController.
ViewController will execute
let gameplayViewCtrl = GameplayViewController()
self.presentViewController(gameplayViewCtrl, animated: true, completion: nil)
in viewDidAppear()
function. So it shows then load another UIViewController
.
GameplayViewController has UICollectionView
as its member. It extends/conforms to UIViewController, UICollectionViewDelegate, UICollectionViewDataSource
. I've linked delegate, datasource, and UICollectionView variable as @IBOutlet properly in storyboard.
With above setup, I tested it. It shows white screen for a sec, then shows black screen. The cells in UICollectionView
in GameplayViewController are never get loaded (no call in code checked via breakpoint). But if I changed the entry point (an arrow in storyboard) to point at GameplayViewController, then it loads properly and show all data in cells. Things work fine.
What's the problem here? I guess it's about event chain that never get caught in non-default UIViewController.
FYI: I do this in xcode 6 beta 3
Updated
I did some more research, and found out there're at least two possible ways to do this. One is my approach, and another is to use segue.
Segue works, you can find how to do it How do I use performSegueWithIdentifier: sender:?. I tested it.
I also tested to switch from GameplayViewController
to ViewController
(reverse from my original test). It showed black screen similar to the first test. But it should show white screen as for ViewController
, it has white background color. This triggers me to think that something's wrong creeping inside.
For now, I use segue approach. But I still want to know why self.presentViewController()
won't do the job for us, and it shows black screen and nothing called or happened.