用iOS解析问题
我正在使用一个解析帐户将图像、消息和用户名发布到一个原型单元。由于某些原因,我的用户名字符串保持为空,因此不会发布到单元格中。你能帮忙吗?我对编码相当陌生,所以这一点让我感到困惑用iOS解析问题,ios,swift,parse-platform,Ios,Swift,Parse Platform,我正在使用一个解析帐户将图像、消息和用户名发布到一个原型单元。由于某些原因,我的用户名字符串保持为空,因此不会发布到单元格中。你能帮忙吗?我对编码相当陌生,所以这一点让我感到困惑 import UIKit import Parse class FeedTableViewController: UITableViewController { var messages = [String]() var usernames = [String]() var imageFil
import UIKit
import Parse
class FeedTableViewController: UITableViewController {
var messages = [String]()
var usernames = [String]()
var imageFiles = [PFFile]()
var users = [String: String]()
var refresher: UIRefreshControl!
@IBAction func logout(sender: AnyObject) {
PFUser.logOut()
var currentUser = PFUser.currentUser()
performSegueWithIdentifier("logout", sender: self)
}
func swiped(gesture:UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizerDirection.Right:
performSegueWithIdentifier("feedSwipe", sender: self)
//case UISwipeGestureRecognizerDirection.Up:
//print("User Swiped Up")
//case UISwipeGestureRecognizerDirection.Down:
//print("User Swiped Down")
case UISwipeGestureRecognizerDirection.Left:
performSegueWithIdentifier("feedSwipe", sender: self)
default:
break
}
}
}
func refresh() {
var query = PFUser.query()
query?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if let users = objects {
self.messages.removeAll(keepCapacity: true)
self.users.removeAll(keepCapacity: true)
self.imageFiles.removeAll(keepCapacity: true)
self.usernames.removeAll(keepCapacity: true)
for object in users {
if let user = object as? PFUser {
self.users[user.objectId!] = user.username!
}
}
}
var getFollowedUsersQuery = PFQuery(className: "followers")
getFollowedUsersQuery.whereKey("follower", equalTo: PFUser.currentUser()!.objectId!)
getFollowedUsersQuery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let objects = objects {
for object in objects {
var followedUser = object["following"] as! String
var query = PFQuery(className: "Post")
query.whereKey("userId", equalTo: followedUser)
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if let objects = objects {
for object in objects {
self.messages.append(object["message"]! as! String)
self.imageFiles.append(object["imageFile"]! as! PFFile)
self.usernames.append(self.users[object["userId"] as! String]!)
//self.usernames.append(followedUser)
self.tableView.reloadData()
self.refresher.endRefreshing()
//print(followedUser)
}
}
})
}
}
}
})
}
override func viewDidLoad() {
super.viewDidLoad()
let swipeRight = UISwipeGestureRecognizer(target: self, action: "swiped:")
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
self.view.addGestureRecognizer(swipeRight)
let swipeUp = UISwipeGestureRecognizer(target: self, action: "swiped:")
swipeUp.direction = UISwipeGestureRecognizerDirection.Up
self.view.addGestureRecognizer(swipeUp)
let swipeDown = UISwipeGestureRecognizer(target: self, action: "swiped:")
swipeDown.direction = UISwipeGestureRecognizerDirection.Down
self.view.addGestureRecognizer(swipeDown)
let swipeLeft = UISwipeGestureRecognizer(target: self, action: "swiped:")
swipeLeft.direction = UISwipeGestureRecognizerDirection.Left
self.view.addGestureRecognizer(swipeLeft)
refresher = UIRefreshControl()
refresher.attributedTitle = NSAttributedString(string: "Pull to refresh")
refresher.addTarget(self, action: "refresh", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refresher)
refresh()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return usernames.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let myCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! cell
imageFiles[indexPath.row].getDataInBackgroundWithBlock { (data, error) -> Void in
if let downloadedImage = UIImage(data: data!) {
myCell.postedImage.image = downloadedImage
}
}
myCell.username.text = usernames[indexPath.row]
myCell.message.text = messages[indexPath.row]
return myCell
}
您提供的代码中没有任何内容与您遇到的问题相关……我想,可能是我的查询在解析过程中出错了……我对编码相当陌生,因此调试此类问题对我来说很困难。