gpt4 book ai didi

ios - 允许按钮在页面 View Controller 中触发新的 View Controller - swift

转载 作者:可可西里 更新时间:2023-11-01 02:04:09 24 4
gpt4 key购买 nike

目前,在我的应用程序中,我有一个页面 View Controller 设置。在页面 View Controller 中,有 3 个不同的 View Controller 。在三个 View Controller 中,有按钮。我希望这些按钮能够触发页面 View Controller 向左或向右移动。

到目前为止,我已经尝试在我的页面 View Controller 中添加一个公共(public)函数,并在另一个 View Controller 中调用它,如下所示:

公共(public)功能:

public func nextViewController(vc: UIViewController) {
HomeRootPageViewController().setViewControllers([vc], direction: .forward, animated: true, completion: nil)

}

在不同的 vc 中点击按钮时调用的函数:

@IBAction func backButton(_ sender: Any) {
HomeRootPageViewController().nextViewController(vc: SocialMediaFeedViewController())
}

当我运行上面的代码时,我收到了这个错误:

UICollectionView: must be initialized with a non-nil layout parameter

基本上,我想知道如何使用按钮来控制 UI 页面 View Controller 的功能。

最佳答案

我猜你不应该传入你用默认初始化 (SocialMediaFeedViewController()) 创建的 VC——这是在 Storyboard中吗?

如果是这样,构造它

 UIStoryboard(name: "SBName", bundle: nil).instantiateViewController(withIdentifier: "SocialMediaFeedViewController"))

如果没有,请按照您初始化它的方式进行初始化,或者如果您仍然有对它的引用,请重用它。

关于ios - 允许按钮在页面 View Controller 中触发新的 View Controller - swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44508730/

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