我在 viewDidLoad 中获取Alamofire的数据,然后将其放入answerArray。但是,在Alamofire连接之前,调用 numberOfRowsInSection 并返回0.如何首先获取Alamofire的数据,然后获取 eventArray.count at numberOfRowsInSection ?
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, "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 }推荐答案
行为正常。 UITableView 委托根据需要调用 numberOfRowsInSection 。
The behavior is normal. UITableView delegate invokes numberOfRowsInSection as needed.
所有你需要触发 self.tableView.reloadData()来刷新表。
All you need is to trigger self.tableView.reloadData() to refresh the table.
Alamofire.request(.POST, "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() }更多推荐
在Alamofire连接之前调用numberOfRowsInSection
发布评论