简体   繁体   English

仅从tableview中的parse.com表填充最后一行

[英]Only populating last row from parse.com table in my tableview

I am hoping someone can help with what I have done wrong :) I have a query that retrieves data from Parse.com. 我希望有人可以帮助我做错了:)我有一个查询从Parse.com检索数据。

After some struggles I have that now working and in the target output I can see all results and I have the correct count of objects. 经过一番挣扎后,我现在正在工作,在目标输出中,我可以看到所有结果,并且我有正确的对象数。

My problem is now I am populating my tableview but only the "last" entry is in the tableview. 我的问题是现在我正在填充我的tableview,但只有“最后”条目在tableview中。 I have tried the reloadData in multiple locations but no luck :( 我已尝试在多个位置的reloadData但没有运气:(

Would appreciate any help if possible. 如果可能的话,将不胜感激。 Thanks in advance 提前致谢

 var TopicPassed:String!
var storedsentences=[getsentences]()

@IBOutlet weak var sentencetableview: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    navlabel.text = TopicPassed

    var query = PFQuery(className:"TalkToMeSentences")
    query.whereKey("Topic", equalTo:TopicPassed)
    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]!, error: NSError!) -> Void in

        if error == nil {
            // query successful - display number of rows found
            println("Successfully retrieved \(objects.count) sentences")



            // print sentences found
            for object in objects {

                let retrievedsentences = object["Sentence"] as NSString
                self.storedsentences = [getsentences(parsesentence: "\(retrievedsentences)")]
                println("\(retrievedsentences) ")
                //self.sentencetableview.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
                //self.sentencetableview.reloadData()

            }

        } else {
            // Log details of the failure
            println("Error: \(error) \(error.userInfo!)")
        }
        //self.sentencetableview.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
        self.sentencetableview.reloadData()
    }
    //self.sentencetableview.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
    //sentencetableview.reloadData()
}

In your loop for object in objects you are setting the value of self.storedsentences each time. for object in objects循环中for object in objects每次都要设置self.storedsentences的值。 At the end of the loop, it will only contain the last value. 在循环结束时,它只包含最后一个值。

Rather, you want to add each item to the array, not replace the array. 相反,您希望将每个项目添加到数组中,而不是替换数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM