0
所以我使用Swift 2和Xcode 7創建了一個應用程序,並使用Parse作爲我的後端服務。 我有兩個視圖控制器,一個PFQueryTableViewController
顯示PFObjects列表,另一個顯示選定單元格的細節。 我想這樣做的方法是將一個唯一的對象ID添加到數組,然後使用didSelectRowAtIndexPath
來執行segue。 但我遇到了在這裏向數組追加元素的問題。加班我追加並打印數組,它顯示元素2次。所以如果正確的數組是[1,2,3,4],那麼我得到的是[1,2,3,4,1,2,3,4],真的很奇怪。在PFQueryTableViewController中附加重複值
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
}
非常感謝! – WhiteRice
歡迎來到StackOverflow!如果您的問題得到解決,請注意,如果有幫助,請標記爲答案 – Russell