gpt4 book ai didi

swift - 单击标签时如何显示另一个 View Controller

转载 作者:行者123 更新时间:2023-11-30 10:42:26 25 4
gpt4 key购买 nike

就像单击按钮显示另一个 View Controller 一样,有没有办法使用标签来做到这一点?

最佳答案

调用下面的函数

注意:请设置与您在下面代码中相同的标识符

class firstViewController: UIViewController {

@IBOutlet weak var yourlabel: UILabel

override func viewDidLoad() {
super.viewDidLoad()

self.addGesture()
}

func addGesture() {

let tap = UITapGestureRecognizer(target: self, action: #selector(self. labelTapped(_:)))
tap.numberOfTapsRequired = 1
self.yourlabel.isUserInteractionEnabled = true
self.yourlabel.addGestureRecognizer(tap)
}

@objc
func labelTapped(_ tap: UITapGestureRecognizer) {

let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let SecondVC = storyboard.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController
self.navigationController?.pushViewController(SecondVC, animated: animated)
}
}

第二个ViewController

class SecondViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
}
}

关于swift - 单击标签时如何显示另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56495194/

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