如何从另一个执行 ViewController 中存在的函数?
How to execute func present in a ViewController from another?
我是Swift的初学者,我还没有完全理解所有的元素。
我正在尝试从另一个 ViewController (ProjectInfosViewController) 中执行存在于 ViewController (ProjectTabBarController) 中的函数。当我从第二个执行函数时出现错误。
对于context来说,它是针对属于一个UITabBarViewController的3个UIViewController的导航按钮,本身嵌入了一个UINavigationController
提前谢谢您! (抱歉我的英语不好)
import UIKit
//MARK:-TAB CONTROLLER
class ProjectTabBarController: UITabBarController {
@IBOutlet weak var ui_saveButton: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func saveAction(_ sender: Any) {
// code
disableSaveButton() // ALL IT'S FINE HERE
}
func enableSaveButton() {
ui_saveButton.title = "Save"
ui_saveButton.isEnabled = true
}
func disableSaveButton() {
ui_saveButton.title = "Saved"
ui_saveButton.isEnabled = false
} }
//MARK:-PROJECT INFORMATIONS
class ProjectInfosViewController: UIViewController, UITextFieldDelegate {
let superController = ProjectTabBarController()
override func viewDidLoad() {
super.viewDidLoad()
}
func textFieldDidChangeSelection(_ textField: UITextField) {
superController.enableSaveButton() // BUT HERE, DOESN'T
} }
//MARK:-PROJECT FIXTURES
class ProjectFixturesViewController: UIViewController, UITableViewDataSource {
}
//MARK:-PROJECT CONTACT
class ProjectContactViewController: UIViewController {
}
这个
let superController = ProjectTabBarController()
是一个新的 vc 没有出现,如果 vc 在 tabController 里面然后做
let res = self.tabBarController as! ProjectTabBarController
res.......// call what you need
我是Swift的初学者,我还没有完全理解所有的元素。
我正在尝试从另一个 ViewController (ProjectInfosViewController) 中执行存在于 ViewController (ProjectTabBarController) 中的函数。当我从第二个执行函数时出现错误。
对于context来说,它是针对属于一个UITabBarViewController的3个UIViewController的导航按钮,本身嵌入了一个UINavigationController
提前谢谢您! (抱歉我的英语不好)
import UIKit
//MARK:-TAB CONTROLLER
class ProjectTabBarController: UITabBarController {
@IBOutlet weak var ui_saveButton: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func saveAction(_ sender: Any) {
// code
disableSaveButton() // ALL IT'S FINE HERE
}
func enableSaveButton() {
ui_saveButton.title = "Save"
ui_saveButton.isEnabled = true
}
func disableSaveButton() {
ui_saveButton.title = "Saved"
ui_saveButton.isEnabled = false
} }
//MARK:-PROJECT INFORMATIONS
class ProjectInfosViewController: UIViewController, UITextFieldDelegate {
let superController = ProjectTabBarController()
override func viewDidLoad() {
super.viewDidLoad()
}
func textFieldDidChangeSelection(_ textField: UITextField) {
superController.enableSaveButton() // BUT HERE, DOESN'T
} }
//MARK:-PROJECT FIXTURES
class ProjectFixturesViewController: UIViewController, UITableViewDataSource {
}
//MARK:-PROJECT CONTACT
class ProjectContactViewController: UIViewController {
}
这个
let superController = ProjectTabBarController()
是一个新的 vc 没有出现,如果 vc 在 tabController 里面然后做
let res = self.tabBarController as! ProjectTabBarController
res.......// call what you need