在我的應用程序的ViewController中,我調用了transitionFromViewController,但在將閉包傳遞給completion:參數時總是得到以下錯誤。如何在Swift中將(可選)完成處理函數閉包傳遞給transitionFromViewController?
Type '() -> Void' does not conform to protocol 'NilLiteralConvertible'
這裏的函數調用:
self.transitionFromViewController(
self.currentVC,
toViewController: newController,
duration: 0.2,
options: UIViewAnimationOptions.TransitionCrossDissolve,
nil,
completion: { finished in
fromViewController.removeFromParentViewController()
toViewController.didMoveToParentViewController(containerViewController)
toViewController.view.frame = containerViewController.view.bounds
})
根據代碼完成方法簽名如下:
transitionFromViewController(fromViewController: UIViewController, toViewController: UIViewController, duration: NSTimeInterval, options: UIViewAnimationOptions, animations:() -> Void(), completion: ((Bool) -> Void)?)
在刪除之前,應根據文檔調用willMoveToParentViewController(nil)! – 2015-11-16 15:02:38