gpt4 book ai didi

ios - 选择器 View 未更新

转载 作者:搜寻专家 更新时间:2023-11-01 07:21:13 25 4
gpt4 key购买 nike

由于一些问题,我正在尝试使用 Alamofire,这里我有一个 Alamofire,它获取在线 JSON 文件,获取四个结果,将它们放在选择器 View 上,并刷新以便它们可以显示。此处的代码完美运行:

 Alamofire.request(.GET, "https://example.com/json.json", parameters: ["foo": "bar"])
.responseJSON { response in
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization

if let JSON = response.result.value {
self.mypickerview.delegate = self
self.mypickerview.dataSource = self
self.pickerData = [JSON["One"] as! String, JSON["Two"] as! String, JSON["Three"] as! String, JSON["Four"] as! String]

self.mypickerview.delegate = self;

}




}

但问题是,使用这段代码,虽然它设法成功获取数据,但它没有显示在选择器 View 中:

// Setup the session to make REST GET call.  Notice the URL is https NOT http!!
let postEndpoint: String = "https://example.com/json.json"
let session = NSURLSession.sharedSession()
let url = NSURL(string: postEndpoint)!

// Make the POST call and handle it in a completion handler
session.dataTaskWithURL(url, completionHandler: { ( data: NSData?, response: NSURLResponse?, error: NSError?) -> Void in
// Make sure we get an OK response
guard let realResponse = response as? NSHTTPURLResponse where
realResponse.statusCode == 200 else {
print("Not a 200 response")
return
}

// Read the JSON
do {
if let ipString = NSString(data:data!, encoding: NSUTF8StringEncoding) {
// Print what we got from the call
print(ipString)

// Parse the JSON to get the data
let jsonDictionary = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
let One = jsonDictionary["One"] as! String
let Two = jsonDictionary["Two"] as! String
let Three = jsonDictionary["One"] as! String
let Four = jsonDictionary["One"] as! String


self.mypickerview.delegate = self
self.mypickerview.dataSource = self
self.pickerData = [One, Two, Three, Four]
self.mypickerview.delegate = self;



}
} catch {
print("bad things happened")
}

}).resume()

阻止选择器 View 中的选项显示的第二个代码可能有什么问题?

最佳答案

紧接着

self.pickerData = [One, Two, Three, Four]

如@SaintThread 在评论中提到的,调用以下命令强制重新加载主线程中的数据

self.mypickerview.reloadAllComponents()

关于ios - 选择器 View 未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38860814/

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