使用未解析的标识符错误

时间:2015-07-29 03:37:06

标签: ios swift parse-platform uicollectionview

我已在我的应用中实施了投票功能,以便用户可以vote发布帖子。我使用collection view并添加了labelbutton。当按下按钮时,投票计数。我在cell view controller中有这个代码。这是我的集合视图控制器,即使我已经说过单元格中的投票我有一个错误说

  

使用未解决的标识符投票

坚持了好几个小时。任何帮助表示赞赏。谢谢。 在cellForItemAtIndexPath我有

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {


    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("newview", forIndexPath: indexPath) as! NewCollectionViewCell
    //cell.backgroundColor = UIColor.blueColor()


    // Display the country name
    if let value = posts[indexPath.row]["imageText"] as? String {
        cell.postsLabel.text = value
        println("it should be there")

    }

    // Display "initial" flag image
    var initialThumbnail = UIImage(named: "question")
    cell.postsImageView.image = initialThumbnail


    // Fetch final flag image - if it exists
    if let value = posts[indexPath.row]["imageFile"] as? PFFile {

        cell.postsImageView.file = value
        cell.postsImageView.loadInBackground({ (image: UIImage?, error: NSError?) -> Void in

            if error != nil {
            }                
        })

        //  let finalImage = tops[indexPath.row]["tops"] as? PFFile

    }

我从此代码中收到错误。

if let value = posts[indexPath.row]["votes"] as? Int {
    if votes == nil {
        votes = 0}
        cell.votesLabel?.text = "\(votes!) votes"

 }

return cell
}

同样在我的手机视图中我也有

@IBAction func vote(sender: AnyObject) {

    if (parseObject != nil) {
        if var votes:Int? = parseObject!.objectForKey("votes") as? Int {
            votes!++

            parseObject!.setObject(votes!, forKey: "votes")
            parseObject!.saveInBackgroundWithTarget(nil, selector: nil)               
            votesLabel?.text = "\(votes!) votes"
    }
    }}}

1 个答案:

答案 0 :(得分:0)

尝试替换以下代码行

if let value = posts[indexPath.row]["votes"] as? Int {
if votes == nil {
    votes = 0}
}

if let votes = posts[indexPath.row]["votes"] as? Int {
if votes == nil {
    votes = 0}
}