【发布时间】:2017-01-17 09:52:21
【问题描述】:
所以我试图在加载视图控制器并设置它时获取一些数据,以便稍后在代码中使用它,但值不会更新。 CountData 值应该是代码底部的 3 但它不是
import UIKit
import Alamofire
class FooController: UIViewController, UITableViewDataSource {
var CountData
override func viewDidLoad() {
super.viewDidLoad();
Alamofire.request("http://foo:8080/joke.php").responseJSON{ response in
if let JSON = response.result.value as? [String: String] {
}
//!!SET DATA HERE!!
self.CountData = 3
}
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//!!USE IT HERE!!
return CountData;
}
【问题讨论】:
-
self.CountData = 3 此行后再次重新加载 tableview