Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios PFQueryTableViewController中追加了重复的值_Ios_Arrays_Swift_Parse Platform - Fatal编程技术网

Ios PFQueryTableViewController中追加了重复的值

Ios PFQueryTableViewController中追加了重复的值,ios,arrays,swift,parse-platform,Ios,Arrays,Swift,Parse Platform,因此,我正在使用Swift 2和Xcode 7创建一个应用程序,并使用Parse作为我的后端服务。 我有两个视图控制器,一个PFQueryTableViewController显示PFObjects列表,另一个显示选定单元格的详细信息。 我认为这样做的方法是将唯一的对象id附加到数组中,然后使用didSelectRowAtIndexPath执行segue。 但是我在数组中添加元素时遇到了问题。当我附加并打印数组时,它会显示元素2次。如果正确的数组是[1,2,3,4],那么我得到的是[1,2,3,

因此,我正在使用Swift 2和Xcode 7创建一个应用程序,并使用Parse作为我的后端服务。 我有两个视图控制器,一个PFQueryTableViewController显示PFObjects列表,另一个显示选定单元格的详细信息。 我认为这样做的方法是将唯一的对象id附加到数组中,然后使用didSelectRowAtIndexPath执行segue。 但是我在数组中添加元素时遇到了问题。当我附加并打印数组时,它会显示元素2次。如果正确的数组是[1,2,3,4],那么我得到的是[1,2,3,4,1,2,3,4],非常奇怪

var arrayOfGameId = [String]()
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
    let cellIdentifier = "cell"

    var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? PFTableViewCell
    if cell == nil {
        cell = PFTableViewCell(style: .Subtitle, reuseIdentifier: cellIdentifier)
    }
    if let object = object {
        cell!.textLabel?.text = object["Title"] as? String
        cell!.detailTextLabel?.text = object["Platform"] as? String
        if let thumbnail = object["Image"]! as? PFFile {
            cell!.imageView!.image = UIImage(named: "game1.png")
            cell!.imageView!.file = thumbnail
        }
        let gameid = object["GameId"] as! String!
        arrayOfGameId.append(gameid)
    }
    print(arrayOfGameId)
    return cell
}
由于您使用的是PFQueryTableViewController,因此无需创建自己的ObjectID列表

从queryForTable返回的PFObjects自动存储在名为objects的列表中

如果需要获取选定对象并转到详图视图控制器,实际上甚至不需要使用didSelectRowAtIndexPath,请尝试以下操作

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using [segue destinationViewController]
    var detailsVC = segue.destinationViewController as! DetailsViewController

    // Pass the selected object to the destination view controller
    if let indexPath = self.tableView.indexPathForSelectedRow() {
        let row = Int(indexPath.row)

        // selectedObject is the PFObject to be displayed
        detailsVC.selectedObject = (objects?[row] as! PFObject)
    }
}

很高兴为您提供帮助,欢迎来到StackOverflow!如果有帮助,请投票,如果问题已经解决,请标记为答案