TableView.reloadData() is not working ? (SWIFT)

前端 未结 3 739
失恋的感觉
失恋的感觉 2021-01-24 10:09

I am developing a Quiz App which fetches questions from a JSON. I have already used reloadData for TableView many times & worked as expected. But now I am fetching Questions

3条回答
  •  独厮守ぢ
    2021-01-24 11:06

    You need to reload your tableview inside Alamofire block

    And so it will look like

      Alamofire.request(.GET, "http://www.wis.com/index.php/capp/chapter_questions_details/\(CourseID)/\(EID)/10")
                .responseJSON { (_, _, data, _) in
                    println(data)
                    let json = JSON(data!)
                    let catCount = json.count
                    for index in 0...catCount-1 {
                        let q = json[index]["QUESTION"].string
                        self.QArray.append(q!)
                        println(self.QArray)
                    }
            self.progress.dismiss()
            self.Exam.reloadData()
      }
    

    and yes ofcourse, as per given answers and comments,

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.QArray?.count ?? 0 // will return 0 rows if QArray is empty
    }
    

    This may help!

提交回复
热议问题