gpt4 book ai didi

ios - layoutIfNeeded() 上的模糊崩溃

转载 作者:行者123 更新时间:2023-11-30 12:42:17 30 4
gpt4 key购买 nike

出现崩溃:

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

有没有办法找到这个展开值在哪里?如果有人有想法,我该如何解决它或者如何更清楚地调试它。谢谢!

最佳答案

正如 Eperrin95 所说,也许您正在尝试布局尚不存在的东西。布局方法应该在 viewDidAppear 之后调用,或者至少在 viewWillAppear 之后调用。

关于ios - layoutIfNeeded() 上的模糊崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42086941/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com