gpt4 book ai didi

ios - 导航 Controller 未加载(push,present)另一个viewController

转载 作者:行者123 更新时间:2023-12-01 19:32:01 24 4
gpt4 key购买 nike

我知道知道已定义的Vc拥有我要显示的VC的值,因此无法在单击按钮时加载viewController。

//AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

let mainViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: "ViewController") as! ViewController
let navVC = UINavigationController.init(rootViewController: mainViewController)
self.window?.rootViewController = navVC
self.window?.makeKeyAndVisible()
return true
}

//ViewController Class
class ViewController: UIViewController, UIScrollViewDelegate {

@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var button: UIButton!
@IBOutlet weak var pageController: UIPageControl!

private let reuseIdentifier = /*"CollectionViewCell"*/ "Cell"
let collectionViewImages : [UIImage] = [#imageLiteral(resourceName: "cooov"), #imageLiteral(resourceName: "shutterstock535739452"), #imageLiteral(resourceName: "portraitYoungManLyingBedCheckingHisFeverThermometer232147948490")]
let collectionViewTexts : [String] = [
"Stay at home ! your health is our Priority",
"Access Latest Coronavirus articles !",
"Check up on your health on a daily basis !"
]

override func viewDidLoad() {
super.viewDidLoad()
renderButton()
renderCell()
pageController.numberOfPages = collectionViewImages.count
pageController.currentPage = 0
}

@IBAction func buttonClicked(_ sender: UIButton) {
let signupVC = UIStoryboard.init(name:"SignUp", bundle: nil).instantiateViewController(withIdentifier: "SignUp")
as! SignUp
self.navigationController?.pushViewController(signupVC, animated: true)
}
}


//SignUp class The VC that should appear on ButtonClick
class SignUp : BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}

//the class that is inherited by ViewController
class BaseViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.isHidden = true
}
}
[enter image description here][1]}
enter image description here
这是提供的图片的链接,请检查。
https://drive.google.com/drive/folders/1CxysH911PIa3-S9Dx6EUV7DE8vlnEd4l?usp=sharing

最佳答案

这是您可以更改的功能,让我知道结果

首先运行这个

@IBAction func buttonClicked(_ sender: UIButton) {
let signupVC = UIStoryboard.init(name:"SignUp", bundle: nil).instantiateViewController(withIdentifier: "SignUp")

let navVC = UINavigationController.init(rootViewController: signupVC)
// self.present(navVC, animated: true, completion: nil)

if let nav = self.navigationController {
nav.pushViewController(navVC, animated: true)
} else {
print("navigation controller not found")
}
}

然后尝试呈现...让我知道发生了什么
@IBAction func buttonClicked(_ sender: UIButton) {
let signupVC = UIStoryboard.init(name:"SignUp", bundle: nil).instantiateViewController(withIdentifier: "SignUp")

let navVC = UINavigationController.init(rootViewController: signupVC)
self.present(navVC, animated: true, completion: nil)


}

关于ios - 导航 Controller 未加载(push,present)另一个viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62228508/

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