我无法在单击按钮时加载视图控制器,因为我知道定义的 Vc 包含我想要呈现的 VC 的值。
//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]}
在此处输入图像描述
这是提供的照片的链接,请检查。 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)
}
你不需要新的UINavigation控制器来推送。
@IBAction func buttonClicked(_ sender: UIButton) {
let signupVC = UIStoryboard.init(name:"SignUp", bundle: nil).instantiateViewController(withIdentifier: "SignUp")
as! SignUp
self.navigationController?.pushViewController(signupVC, animated: true)
}
此外,如果您正在使用iOS 13.0 +并使用Xcode 11 +,则您的 将调用SceneDelegate 而不是 AppDelegate。因此,请尝试将粘贴内容复制到 SceneDelegate。