Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

Instantiate ViewController crashing on iOS 13

App is crashing because of instantiateViewController() and it seems to affect iOS 13 users only.

let homeTabBarController = storyboard?.instantiateViewController(identifier: "home") as! HomeTabBarController

HomeTabBarController is a subclass UITabBarController. If I use a subclass of ViewController it works perfectly fine.

question from:https://stackoverflow.com/questions/65713215/instantiate-viewcontroller-crashing-on-ios-13

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It’s because viewController storyboard is maybe nil at that time, try this

var myViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("myViewControllerIdentifier") as! ViewController

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...