gpt4 book ai didi

ios - 如何从自身呈现相同的当前 View Controller

转载 作者:行者123 更新时间:2023-11-29 05:37:45 24 4
gpt4 key购买 nike

我正在制作一个应用程序,每次按下下一个按钮时 Storyboard的文本都会更改,但我希望每次按下下一个按钮时都有一个segue类型的动画

我尝试调用一个通向 View Controller 的segue,但它调用了SIGABART

    public func segue() {

var slide: [String] = GetText().Main(text: .info(0, 0))

print(slide)

SectionViewController().setValues(title: slide[1], buttonTitle: slide[3], body: slide[2])

performSegue(withIdentifier: slide[0], sender: nil)
}

我也尝试过

let vc = SectionViewController() //my view controller class
self.present(vc, animated: true, completion: nil)

但它说线程1: fatal error :隐式解包可选值时意外发现nil当尝试更新标签时

我预计 View Controller 会再次弹出动画,但它会因 SIGABART 崩溃,可能是因为 View Controller 不“拥有”segue

最佳答案

不要使用Segue,而是从SectionViewController以编程方式呈现另一个SectionViewController实例,例如,

class SectionViewController: UIViewController {
@IBOutlet weak var label: UILabel!

func setValues(title: String, buttonTitle: String) {
label.text = title
//add your code...
}

func showSectionVC() {
if let vc = self.storyboard?.instantiateViewController(withIdentifier: "SectionViewController") as? SectionViewController {
vc.setValues(title: "", buttonTitle: "")
self.present(vc, animated: true, completion: nil)
}
}
}

从您想要在已呈现的 SectionViewController 中呈现 SectionViewController 的任何位置调用 showSectionVC()

另外,不要忘记正确连接SectionViewControllerlabeloutlet

关于ios - 如何从自身呈现相同的当前 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56866628/

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