gpt4 book ai didi

ios - 实例化初始 View Controller 提供 Nil

转载 作者:行者123 更新时间:2023-11-28 15:11:19 24 4
gpt4 key购买 nike

对于我的标签栏 Controller ,我想要 4/5 标签的过渡。第五个选项卡我能够成功执行不同的转换,但尝试将其添加到其他 View Controller 导致崩溃。

Action Storyboard: This storyboard contains my tab bar controller, and my camera view controller. The transition for this view controller is the only one that works. When i try to transition different tabs that are not in the tab bar controllers storyboard, it crashes

Storyboard that contains tab bar controller

这是有问题的 Storyboard

For example, I want to provide a different transition for the view controller in this storyboard. However, i get the error:Unexpectedly found nil while unwrapping an optional valueHome Storyboard

这是我的代码:

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if let restoreID = viewController.restorationIdentifier {
if restoreID == "NavigationCamera" {
// This is the transition that works
if let nav = tabBarController.viewControllers![tabBarController.selectedIndex] as? UINavigationController {
print("Nav is allowed")
let newVC = tabBarController.storyboard?.instantiateViewController(withIdentifier: "CameraView")
let transition = CATransition()
transition.duration = 0.25
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromTop
nav.view.layer.add(transition, forKey: nil)
nav.pushViewController(newVC!, animated: false)
return false
}
} else {
if let otherNav = tabBarController.viewControllers![tabBarController.selectedIndex] as? UINavigationController {
print("Other nav is allowed")
let vcID = restoreID + "View"
print(vcID)
let myVC = otherNav.storyboard?.instantiateInitialViewController()
let otherTransition = CATransition()
otherTransition.duration = 0.25
otherTransition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
otherTransition.type = kCATransitionPush
otherTransition.subtype = kCATransitionFade
otherNav.view.layer.add(otherTransition, forKey: nil)
// This is where the error occurs and crashes
otherNav.pushViewController(myVC!, animated: false)
return false
}
}
}
return true
}

我再次得到的错误是:

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

最佳答案

let storyboard = UIStoryboard(name: <other storyboard>, bundle: nil)
let myVC = storyboard.instantiateViewController(withIdentifier: <your navigation controler>)

关于ios - 实例化初始 View Controller 提供 Nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47588214/

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