解析不返回用户名列表

时间:2015-11-16 22:00:43

标签: ios swift parse-platform

由于某种原因,我无法获取我输入的用户名以显示在我的tableview中。有任何想法吗?我仔细检查了我的单元格的名称,解析时类的名称以及列的名称。也许我忘记了什么?

import UIKit

import Parse




class AddFriendViewController: UIViewController, UITableViewDataSource,    UITableViewDelegate, UISearchBarDelegate {

@IBOutlet var myFriendSearchBar: UISearchBar!
@IBOutlet var myFriendSearchList: UITableView!


var searchResult = [String]()

override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationController?.navigationBar.barTintColor = UIColor.blackColor()
    self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
    self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "Nexa Rust Script L", size: 25)!,  NSForegroundColorAttributeName: UIColor.whiteColor()]
    self.myFriendSearchBar.delegate = self


    self.navigationItem.title = "Haffla"
    navigationController?.setNavigationBarHidden(false, animated: true)

    // Do any additional setup after loading the view.
}

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


 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
 {
    return searchResult.count
}



func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let myCell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) as UITableViewCell

    myCell.textLabel?.text = searchResult[indexPath.row]

    return myCell

}
func searchBarSearchButtonClicked(searchBar: UISearchBar) {
    myFriendSearchBar.resignFirstResponder()

    let userName = PFQuery(className: "User")
    userName.whereKey("username", containsString: searchBar.text)
    let query = PFQuery.orQueryWithSubqueries([userName])


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


        if error != nil {

            let myAlert = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: UIAlertControllerStyle.Alert)


            let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)


            myAlert.addAction(okAction)

            self.presentViewController(myAlert, animated: true, completion: nil)

            return
        }
        if let friends = objects as [PFObject]? {
            self.searchResult.removeAll(keepCapacity: false)

            for object in friends {


                let username = object.objectForKey("username") as! String
                self.searchResult.append(username)


            }
            dispatch_async(dispatch_get_main_queue()) {
                self.myFriendSearchList.reloadData()
                self.myFriendSearchBar.resignFirstResponder()
            }

        }



    }

}






func searchBarCancelButtonClicked(searchBar: UISearchBar) {
    myFriendSearchBar.resignFirstResponder()
    myFriendSearchBar.text? = ""
}



}

我收到此错误:快照未呈现的视图会导致空快照。确保您的视图在屏幕更新后的快照或快照之前至少呈现一次。

1 个答案:

答案 0 :(得分:0)

我找到了!!!!我正在查看错误的Parse类,我应该引用用户解析类:

var something: PFQuery = PFUser.query()!