我想創建一個投票系統,並將其存儲到我的後端,並讓它爲每個單獨的圖片出現並存儲爲每張圖片。我在我的後端Parse中創建了一個名爲「count」的列,但我似乎無法得到投票或保存在後面的投票並添加。我正在使用一個swipeGestureRecognizer來啓動一個左上角的投票權,但我無法在 - =和+ =的switch語句中獲得正確的語法,並且我得到了二元運算符錯誤'+ ='/' - ='不能應用於'[(Int)]'和'Int'類型的操作數,我該如何讓投票系統既能保存在後端,又能被提出並顯示每張個人圖片投票?試圖讓我的投票系統工作,並在解析中登錄後端
import UIKit
import Parse
class HomePage: UITableViewController {
var images = [UIImage]()
var titles = [String]()
var imageFile = [PFFile]()
var count = [Int]()
override func viewDidLoad() {
super.viewDidLoad()
println(PFUser.currentUser())
var query = PFQuery(className:"Post")
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock {(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
println("Successfully retrieved \(objects!.count) scores.")
println(objects!)
for object in objects! {
if let title = object["Title"] as? String {
self.titles.append(title)
}
if let imgFile = object["imageFile"] as? PFFile {
self.imageFile.append(imgFile)
}
if let voteCounter = object["count"] as? Int {
self.count.append(voteCounter)
}
self.tableView.reloadData()
}
} else {
// Log details of the failure
println(error)
}
}
}
/* println("Successfully retrieved \(objects!.count) scores.")
for object in objects! {
self.titles.append(object["Title"] as! String)
self.imageFile.append(object["imageFile"] as! PFFile)
self.tableView.reloadData()
}*/
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return titles.count
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 500
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var myCell:cell = self.tableView.dequeueReusableCellWithIdentifier("myCell") as! cell
myCell.rank.text = "21"
myCell.votes.text = "\(count)"
myCell.postDescription.text = titles[indexPath.row]
imageFile[indexPath.row].getDataInBackgroundWithBlock { (data, error) -> Void in
if let downloadedImage = UIImage(data: data!) {
myCell.postedImage.image = downloadedImage
}
}
var swipeRight = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
myCell.postedImage.userInteractionEnabled = true;
myCell.postedImage.addGestureRecognizer(swipeRight)
var swipeLeft = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeRight.direction = UISwipeGestureRecognizerDirection.Left
myCell.postedImage.userInteractionEnabled = true;
myCell.postedImage.addGestureRecognizer(swipeLeft)
return myCell
}
func respondToSwipeGesture(gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizerDirection.Right:
count += 1
println("Swiped right")
case UISwipeGestureRecognizerDirection.Left:
count -= 1
println("Swiped Left")
default:
break
}
}
}
}
這是我現在有,但投票仍不會得到登錄到解析和post.count + = 1和post.count- = 1接收「PFObject」的錯誤消息,沒有一個成員命名爲'count',我哪裏錯了?
我確實把它保存在我的postImageView中作爲一個PFObject,我相信所以在這個tableview中一切都不是PFObject的子類? – DanielWolfgangTrebek
是否有任何快捷的文檔即時通訊客戶不熟悉c – DanielWolfgangTrebek
是的,在這裏你可以切換到Swift版本:https://parse.com/docs/ios/guide –