Reputation: 3930
I'll start with the main problem: My issue is not easily reproducible.
So... In my app, depending on whether it's the first time the user opens it, I am changing the rootViewController.
I do so like this:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if /* code to figure out if it's the first launch */ {
let storyboard = UIStoryboard(name: "Onboarding", bundle: nil)
let onboardingViewController = storyboard.instantiateInitialViewController()
window?.rootViewController = onboardingViewController
}
return true
}
}
And this basically works great! As I am currently building that Onboarding ViewController, I removed the if and therefore it always get's displayed. This also worked fine, but all of a sudden the app would not start any more. The screen stays black. I then run the exact same code on an other device and it's working there. Btw. the code above is all there is in my AppDelegate and the issues persists if the OnboardingVC has everything commented out.
When looking at the UI-Debugger for my app it also looks strange:
Normally there would be an arrow next to the UIWindow showing that it's root is indeed my VC, but in my case that's not the case.
I wouldn't mind and just delete the app from my device and reinstall it afterwards, but I've had one user-complaint for an other app of mine which users the same logic, who told me about the exact problem. Now I basically reproduced the issue but have no idea on where the problem should be.
My app is using storyboards btw.
Maybe somebody had that problem before and has any idea on what might be the problem.
EDIT:
Just had the problem again today... Here are some more observations: When I initiate my ViewController and output it's view, it's not correct. It's not the view that is really set in the storyboard. It's a random other view. Is it possible, that the storyboard is corrupt? And if so... what can I do about it? After I added a random subview to my Main-View-Controllers view and run again, it worked again... So obviously the storyboard somehow got corrupt?
Ok... while development... ok... but for an app that's out there and all of a sudden the storyboard get's corrupt... that is really bad!!!!
Did anybody have that problem before? And how to solve it?
Upvotes: 0
Views: 2180
Reputation: 3930
I've finally figured out the problem. For whatever reason I obviously double-linked the view outlet of my Initial-View-Controller to a subview. So it had two outlets to the view property (how is that even possible?) And it randomly picked on or the other on startup.... Took a very sharp eye of a friend to see the problem :)
Upvotes: 0
Reputation: 2446
try this in your case window is nil so
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height))
if /* code to figure out if it's the first launch */ {
let storyboard = UIStoryboard(name: "Onboarding", bundle: nil)
let onboardingViewController = storyboard.instantiateInitialViewController()
window?.rootViewController = onboardingViewController
}
return true
}
}
Upvotes: 1