Swift 使用其他后续用户的用户名填充表

Swift 使用其他后续用户的用户名填充表,swift,parse-platform,Swift,Parse Platform,我不断得到致命错误: 在展开可选值时意外发现nil 我需要做什么 希望找到我搞砸的地方。有很多?在代码中: 第一:您正在尝试使用currentUser(用户名)或(objectID)进行查询吗 第二:在FindObjectsInBackgroundithBlock方法中 首先需要检查是否存在错误,然后将任何对象的数组转换为PFObject class FollowingTableTableViewController: UITableViewController { let usernames

我不断得到致命错误:

在展开可选值时意外发现nil

我需要做什么


希望找到我搞砸的地方。

有很多?在代码中:

第一:您正在尝试使用currentUser(用户名)或(objectID)进行查询吗

第二:在FindObjectsInBackgroundithBlock方法中 首先需要检查是否存在错误,然后将任何对象的数组转换为PFObject

class FollowingTableTableViewController: UITableViewController {

let usernames = NSMutableArray()


override func viewDidLoad() {
    super.viewDidLoad()
    getUsernames()

    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem()
}

func getUsernames() {

    var user1 = PFUser.currentUser()
    var findUsernames:PFQuery = PFQuery(className: "FollowRequests")
    findUsernames.whereKey("from", equalTo: user1!)
    findUsernames.includeKey("to")

    findUsernames.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in

        var myObjects = objects as! [PFObject]

        //Solve this part. Need to get all of the users from the "to" field in FollowRequests.

        //If No error
        if (error == nil) {
            for myObjects in objects! {
                var user2 = PFUser()
                user2.objectForKey("to")
                self.usernames.addObject(user2.username!)
                println(user2.username)
            }
            self.tableView.reloadData()
        }

    }

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return self.usernames.count
}

override func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath)
    -> UITableViewCell {
        let item: AnyObject = self.usernames[indexPath.row]

        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
        cell.textLabel!.text = (usernames[indexPath.row] as! String)
        return cell
}
}

第三:在cellforrowatinexpath方法中 你为什么有那条额外的线

if error  == nil{
if let objects = objects as! [PFObject]{
   for oneSpecificObject in objects{
     var data = oneSpecificObject["to"] as! String  
      self.usernames.addObject(data)
     }
  self.tableView.reloadData()
}   

//仔细检查您的代码,如果您仍然有问题,请告诉我。

有很多问题吗?在代码中:

第一:您正在尝试使用currentUser(用户名)或(objectID)进行查询吗

第二:在FindObjectsInBackgroundithBlock方法中 首先需要检查是否存在错误,然后将任何对象的数组转换为PFObject

class FollowingTableTableViewController: UITableViewController {

let usernames = NSMutableArray()


override func viewDidLoad() {
    super.viewDidLoad()
    getUsernames()

    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem()
}

func getUsernames() {

    var user1 = PFUser.currentUser()
    var findUsernames:PFQuery = PFQuery(className: "FollowRequests")
    findUsernames.whereKey("from", equalTo: user1!)
    findUsernames.includeKey("to")

    findUsernames.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in

        var myObjects = objects as! [PFObject]

        //Solve this part. Need to get all of the users from the "to" field in FollowRequests.

        //If No error
        if (error == nil) {
            for myObjects in objects! {
                var user2 = PFUser()
                user2.objectForKey("to")
                self.usernames.addObject(user2.username!)
                println(user2.username)
            }
            self.tableView.reloadData()
        }

    }

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return self.usernames.count
}

override func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath)
    -> UITableViewCell {
        let item: AnyObject = self.usernames[indexPath.row]

        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
        cell.textLabel!.text = (usernames[indexPath.row] as! String)
        return cell
}
}

第三:在cellforrowatinexpath方法中 你为什么有那条额外的线

if error  == nil{
if let objects = objects as! [PFObject]{
   for oneSpecificObject in objects{
     var data = oneSpecificObject["to"] as! String  
      self.usernames.addObject(data)
     }
  self.tableView.reloadData()
}   

//仔细检查您的代码,如果仍然有问题,请告诉我。

请尝试使用当前用户名或IDXcode查找查询,通常Xcode会突出显示导致错误的行,你也可以分享吗?查询按用户名进行确定你看到我的建议了吗?你现在正在查看它。如果你尝试使用当前用户名或IDXcode查找查询,通常会突出显示导致错误的行,你也可以分享吗?查询按用户名进行确定你看到我的建议了吗。