0

Working on a questions and answer app similar to Quora. Moving from Parse to Backendless.

The app compiles, I see data in the output, but the tableview is empty. the data isnt appending the array? (using Swift 2, Xcode 7.2)

    import UIKit


class QuestionsTableViewController: UITableViewController {

    let backendless = Backendless.sharedInstance()
    var showAllQuestions = [String]()
    //var showAllQuestions = [String:AnyObject] = [Question]() as [String:AnyObject]
    var currentQuestion = [Question]()

    override func viewDidLoad() {
        super.viewDidLoad()

        Types.tryblock({ () -> Void in

            let startTime = NSDate()
            let query = BackendlessDataQuery()
            var allQuestions = self.backendless.persistenceService.of(Question.ofClass()).find(query)
            print("Total Questions in the Backendless starage - \(allQuestions.totalObjects)")

            let bc1 : BackendlessCollection = allQuestions as BackendlessCollection
            for order : Question in bc1.data as! [Question] {

                self.showAllQuestions.appendContentsOf(self.showAllQuestions)
                self.tableView.reloadData()

            }
            var size = allQuestions.getCurrentPage().count
            while size > 0 {
                print("Loaded \(allQuestions) questions in the current page")
                allQuestions = allQuestions.nextPage()
                size = allQuestions.getCurrentPage().count
            }

            print("Total time (ms) - \(1000*NSDate().timeIntervalSinceDate(startTime))")
            },

            catchblock: { (exception) -> Void in
                print("Server reported an error: \(exception as! Fault)")
            }
        )

    }

   override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

       return showAllQuestions.count
    }

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCellWithIdentifier("questionCell",
            forIndexPath: indexPath) as! QuestionsTableViewCell


        cell.userNameLabel.text = showAllQuestions[indexPath.row]
        cell.questionLabel?.text = showAllQuestions[indexPath.row]


        return cell
    }

This outputs this:

Total Questions in the Backendless starage - 8

Loaded <BackendlessCollection> -> type: BloQuery2.Question, offset: 0, pageSize: 100, totalObjects: 8, data: ( "<BloQuery2.Question: 0x7faab60091f0>", "<BloQuery2.Question: 0x7faab3e1f280>", "<BloQuery2.Question: 0x7faab600aae0>", "<BloQuery2.Question: 0x7faab600bbf0>", "<BloQuery2.Question: 0x7faab600cd80>", "<BloQuery2.Question: 0x7faab600ddf0>", "<BloQuery2.Question: 0x7faab600eeb0>", "<BloQuery2.Question: 0x7faab600ffa0>" ), query: <BackendlessDataQuery> -> properties: (null), whereClause: (null), queryOptions: <QueryOptions> -> { offset = 0; pageSize = 100; related = ( ); } questions in the current page Total time (ms) - 1122.19899892807

4

2 回答 2

0

请更改代码

覆盖 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

  let blocQuery:BloQuery2 = showAllQuestions[indexPath.row] as BloQuery2
    let onequestion:Question = blockQuery.Question as Question
    cell.userNameLabel.text = onequestion.userName as? String
    cell.questionLabel?.text = onequestion.question as String
于 2016-02-10T09:16:43.137 回答
0

“self.allQuestions”中有哪些数据?它不是作为字符串出现的。它是 BloQuery2.Question 类型 请通过任何函数更改类型以从“BloQuery2.Question”获取值作为字符串。

于 2016-02-10T09:00:23.343 回答