【发布时间】:2020-09-25 10:29:59
【问题描述】:
我无法在单击按钮时加载 viewController,因为我知道定义的 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
【问题讨论】:
-
如果您尝试推送 viewController,则不需要 buttonClicked 内的第二行,您将在其中实例化新的 UINavigationController。
-
试过了还是不行
-
哪个类有按钮?
-
您在 appDelegate 中有
buttonClicked代码? -
你的
buttonClicked代码正在执行吗?
标签: ios swift xcode uiviewcontroller uinavigationcontroller