如何使用按钮和文本字段移动到其他 View Controller ?
我有超过 100 个 View Controller 。
例如
如果用户在文本字段中输入 10 并单击旁边的按钮,他可以移动到 Storyboard ID 为“10”的 View Controller
或者,如果用户在文本字段中输入 77,他可以移动到 Storyboard ID 77 的 View Controller 。
或者类似这样...
谢谢。
最佳答案
您应该能够通过执行以下操作来完成此操作:
@IBAction func textFieldButton(_ sender: UIButton) {
let vc = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: textfield.text!)
self.present(vc, animated: true, completion: {})
}
摘要
只要 ViewController 的 ID 与文本字段中输入的内容相匹配,就可以解决问题。您可能需要添加额外的代码来验证输入的内容。
关于swift - 如何使用按钮和文本字段移动到其他 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57313471/