Аварии, как представляется, это:Obscure аварии на layoutIfNeeded()
navigationController.view.layoutIfNeeded()
log : fatal error: unexpectedly found nil while unwrapping an Optional value
Катастрофа появляется при первом запуске приложения (после Xcode сборки), и когда мой пользователь отключить и снова от его счет. Если я перезапущу приложение с уже подключенным пользователем, это будет нормально.
Полный код функции:
func prepareControllers(){
homeTabs = [homeView, teamView, rankView, generalView]
for view in homeTabs{
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ABMainViewController.didTapTab(_:))))
}
mainControllers = [
UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "home") as! ABHomeViewController,
UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "teamController") as! ABTeamViewController,
UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "leaderboardController") as! ABLeaderboardViewController,
ABInformationViewController(nibName: "ABInformationViewController", bundle: Bundle.main)
]
var previousController: UINavigationController? = nil
for viewController in mainControllers{
viewController.delegate = self;
let navigationController = UINavigationController(rootViewController: viewController)
navigationControllers.append(navigationController)
navigationController.view.frame = scrollView.bounds
navigationController.setNavigationBarHidden(true, animated: false)
navigationController.view.translatesAutoresizingMaskIntoConstraints = false
scrollView.addSubview(navigationController.view)
scrollView.addConstraint(NSLayoutConstraint(item: navigationController.view, attribute: .top, relatedBy: .equal, toItem: scrollView, attribute: .top, multiplier: 1, constant: 0))
scrollView.addConstraint(NSLayoutConstraint(item: navigationController.view, attribute: .height, relatedBy: .equal, toItem: scrollView, attribute: .height, multiplier: 1, constant: 0))
scrollView.addConstraint(NSLayoutConstraint(item: navigationController.view, attribute: .width, relatedBy: .equal, toItem: scrollView, attribute: .width, multiplier: 1, constant: 0))
if(previousController != nil){
scrollView.addConstraint(NSLayoutConstraint(item: navigationController.view, attribute: .left, relatedBy: .equal, toItem: previousController!.view, attribute: .right, multiplier: 1, constant: 0))
}else{
scrollView.addConstraint(NSLayoutConstraint(item: navigationController.view, attribute: .leading, relatedBy: .equal, toItem: scrollView, attribute: .leading, multiplier: 1, constant: 0))
}
navigationController.view.layoutIfNeeded() // CRASH HERE
previousController = navigationController
}
scrollView.addConstraint(NSLayoutConstraint(item: scrollView, attribute: .trailing, relatedBy: .equal, toItem: previousController!.view, attribute: .trailing, multiplier: 1, constant: 0))
}
В отладки навигатора:
0x102b691f8 <+116>: bl 0x102a5cb80 ; function signature specialization <preserving fragile attribute, Arg[1] = [Closure Propagated : reabstraction thunk helper from @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) ->() to @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@out()), Argument Types : [@callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) ->()]> of generic specialization <preserving fragile attribute,()> of Swift.StaticString.withUTF8Buffer <A> ((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A
-> 0x102b691fc <+120>: brk #0x1 //HERE
есть способ нашел, где это разворачивание значение? Если у кого-то есть идея, как я могу ее решить или как я могу отлаживать ее более четко. Благодаря !
ваш авария примерно _ «неожиданно найден« nil »при развертывании необязательного значения« _; поэтому зададимся вопросом: проверили ли вы все случаи явного разворачивания необязательного, могут ли они быть развернуты явно без сбоев? если нет, почему бы и нет? – holex