我将Xcode更新为7.3。在更新之前,我可以在运行代码时出现任何错误或崩溃。更新后,当我在iPhone上运行以下代码时,我得到了断言错误(有趣的是,模拟器上没有错误)。
let storyboard = UIStoryboard(name: storyboard, bundle: nil)
self.window?.rootViewController = storyboard.instantiateInitialViewController() as UIViewController!
错误
2016-03-24 16:15:25.891 Zilingo[434:92251] *** Assertion failure in -[UIStoryboard instantiateViewControllerWithIdentifier:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.7/UIStoryboard.m:171
error: Execution was interrupted, reason: breakpoint 5.1.
The process has been returned to the state before expression evaluation.
我是不是错过了更新的某个步骤?
Try to this format:-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// get your storyboard
let storyboard = UIStoryboard(name: "Main", bundle: nil)
// instantiate your desired ViewController
let rootController = storyboard.instantiateViewControllerWithIdentifier("MyViewController") as! UIViewController
// Because self.window is an optional you should check it's value first and assign your rootViewController
if let window = self.window {
window.rootViewController = rootController
}
return true
}
我遇到了同样的问题。在我的情况下,我忘记添加标识符字符串。让vc=storyboard.instantiateViewControllerWithIdentifier(")为!UIViewController
我像上面那样写的。我忘了添加标识符。在我添加标识符后,它就工作了。