[英]View controller's data changes on 2nd attempt
Hey my code changes data in another view controller on 2nd attempt on 1st just showing default values嘿,我的代码在第一次尝试第二次时更改了另一个视图控制器中的数据,仅显示默认值
Code inside button按钮内的代码
@IBAction func check(_ sender: Any) {
makeRequest()
let fin = UIStoryboard(name: "FinalViewController", bundle: nil)
let pop = fin.instantiateInitialViewController()! as! FinalViewController
pop.img = icon
pop.state = state
pop.fail = failed
self.present(pop, animated: true)
}
Code inside 2nd view controller第二个视图控制器内的代码
class FinalViewController: UIViewController {
@IBOutlet weak var weathure_icon: UIImageView!
@IBOutlet weak var status: UILabel!
var fail = false
var img = ""
var state = ""
override func viewDidLoad() {
if fail == false{
super.viewDidLoad()
status.text = state
weathure_icon.image = UIImage(named: img+".png")
}
}
Please check three things in your code inside the button action.请检查按钮操作中代码中的三件事。
Please cross-check, is makeRequest() asynchronous request??请交叉检查, makeRequest() 是异步请求吗??
is icon, state and failed parameters request coming from makeRequest() method, in this case you need to handle request data on main thread.是来自makeRequest()方法的图标、状态和失败参数请求,在这种情况下,您需要在主线程上处理请求数据。
Please replace following in your code:请在您的代码中替换以下内容:
This这个
let fin = UIStoryboard(name: "FinalViewController", bundle: nil) let pop = fin.instantiateInitialViewController()! let fin = UIStoryboard(name: "FinalViewController", bundle: nil) let pop = fin.instantiateInitialViewController()! as!
作为! FinalViewController
最终视图控制器
With和
let fin = UIStoryboard(name: "STORYBOARD_NAME", bundle: nil) let pop = fin.instantiateInitialViewController(identifier: "FinalViewController")! let fin = UIStoryboard(name: "STORYBOARD_NAME", bundle: nil) let pop = fin.instantiateInitialViewController(identifier: "FinalViewController")! as!
作为! FinalViewController
最终视图控制器
Hope this will help you and make success with your implementation :)希望这会帮助您并在您的实施中取得成功:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.