[英]use of unresolved identifier error
I have implemented a vote feature in my app so that user can vote
up a post. 我在我的应用程序中实现了投票功能,以便用户可以对帖子进行
vote
。 I am using a collection view
and have put a label
and a button
. 我正在使用
collection view
,并放置了label
和button
。 When the button is pressed the vote counts up. 当按下按钮时,投票数增加。 I have that code in the
cell view controller
. 我在
cell view controller
有该代码。 This is my collection view controller and even though I have said that votes in the cell I have an error saying 这是我的集合视图控制器,尽管我已经说过单元格中的投票,但我仍然出错
use of unresolved identifier votes
使用未解决的标识符票
Stuck for many hours. 卡了好几个小时。 Any help is appreciated..Thank you.
感谢您的帮助。谢谢。 In the
cellForItemAtIndexPath
I have 在
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
}
I get an error from this code. 我从此代码中得到一个错误。
if let value = posts[indexPath.row]["votes"] as? Int {
if votes == nil {
votes = 0}
cell.votesLabel?.text = "\(votes!) votes"
}
return cell
}
Also in my cell view I also have 在单元格视图中我也有
@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"
}
}}}
Try replacing below lines of code 尝试替换下面的代码行
if let value = posts[indexPath.row]["votes"] as? Int {
if votes == nil {
votes = 0}
}
with 与
if let votes = posts[indexPath.row]["votes"] as? Int {
if votes == nil {
votes = 0}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.