大家都从服务器获取数据,即:
{
error = 0;
"error_msg" = "Successfully Login";
success = 1;
user = {
DriverID = 35;
DriverName = "Home nath";
"com_id" = 2;
};
}
现在我需要将DriverName的数据传递给标签box.how中的其他视图控制器来执行此操作吗?
答案 0 :(得分:2)
在目标视图控制器中创建一个string类型的变量。
<强> DestinationViewController.Swift 强>
class DestinationViewController: UIViewController {
var driverName: String?
override func viewDidLoad() {
super.viewDidLoad()
print(driverName)
}
}
<强> CurrentViewController.swift 强>
在CurrentViewController中覆盖prepareForSegue:sender:
方法。
class CurrentViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destnationVC = segue.destination as! DestinationViewController
destnationVC.driverName = "Home nath"
}
}
学习如何将数据从CurrentViewController传递到DestinationViewController和DestinationViewController到OrignViewController,它会帮助你。