I get data by Alamofire in viewDidLoad
, then put it into answerArray. However, before Alamofire connection, the numberOfRowsInSection
is invoked and returns 0. How can I get data by Alamofire first, then get eventArray.count
at numberOfRowsInSection
?
var answerArray = NSMutableArray()
override func viewDidLoad() {
let parameters = [
"id":questionNum
]
Alamofire.request(.POST, "http://localhost:3000/api/v1/questions/question_detail",parameters: parameters, encoding: .JSON)
.responseJSON { (request, response, JSON, error) in
println(JSON!)
// Make models from JSON data
self.answerArray = (JSON!["answers"] as? NSMutableArray)!
}
self.tableView.reloadData()
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return answerArray.count
}