场景:从上一个 tableView 点击传入 uid ,然后在 viewDidLoad 里面做数据查询,最后展示到 tableView 中。
问题:用 Alamofire 做 GET 请求得到结果,但在 Alamofire 打印结果条数为 0 ,在 Alamofire 内打印有结果条数。具体请看代码
class SealViewController: UITableViewController {
var userId: String!
var seals: [SealModel] = []
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
print("uid->", userId)
//加在公告 json 数据
Alamofire.request(.GET, SERVICEAPIDOMAIN + "/Mobile/MobileHandler.ashx?method=toAudit&uid=" + userId).responseJSON {
response in
if let apiData = response.result.value {
let json = JSON(apiData)
for var i = 0; i < json["items"].count; i++ {
let line = json["items"][i]
self.seals.append(SealModel(id: line["ID"].stringValue, title: line["TitleStr"].stringValue, content: line["ContentStr"].stringValue, dateTime: line["TimeStr"].stringValue, type: line["Type"].stringValue))
}
}
print("Alamofire-sealsCount->", self.seals.count)
}
tableView.reloadData()
print("sealsCount->", self.seals.count)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
打印输出结果
uid-> 69
sealsCount-> 0
Alamofire-sealsCount-> 12
如何让才能让 sealsCount 打印输出的时候就有结果?