在Alamofire连接之前调用numberOfRowsInSection

编程入门 行业动态 更新时间:2024-10-28 17:18:47
本文介绍了在Alamofire连接之前调用numberOfRowsInSection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 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

本文发布于:2023-11-26 15:05:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634215.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Alamofire   numberOfRowsInSection

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!