0

I cannot for some reason get the username i typed to display in my tableview. Any ideas? I triple checked the name of my cell, the name of class on parse and the name of the column. Maybe i forgot something?

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? = ""
}



}

i got this error:Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.

Nathannn
  • 161
  • 4
  • 16
  • Try `username.findObjectsInBackgroundWithBlock...` – Craig Siemens Nov 16 '15 at 22:21
  • Did you set delegate and dataSource for your tableview to AddFriendViewController? – Moriya Nov 16 '15 at 22:23
  • that did not work :/ @CleverError – Nathannn Nov 16 '15 at 22:32
  • i got this error: Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates. @Moriya – Nathannn Nov 16 '15 at 22:34
  • Seems like a strange error for this post but check out this link. It might help: http://stackoverflow.com/questions/25884801/ios-8-snapshotting-a-view-that-has-not-been-rendered-results-in-an-empty-snapsho – Moriya Nov 16 '15 at 22:37
  • I am not trying to take a snapshot, maybe i hit the wrong button. Between what button is the function: searchBarSearchButtonClicked(searchBar: UISearchBar) @Moriya – Nathannn Nov 16 '15 at 22:40
  • I'm afraid I can not help you. I haven't used parse myself and the only thing I can see that might be wrong is the delegate and data source for table view. Perhaps you can try to set them in code and see if that might help. – Moriya Nov 16 '15 at 22:43
  • i found it!!!! i was looking at the wrong Parse class and i should refer to the user parse class with: var something: PFQuery = PFUser.query()! @Moriya – Nathannn Nov 17 '15 at 00:05

1 Answers1

0

i found it!!!! i was looking at the wrong Parse class and i should refer to the user parse class with:

var something: PFQuery = PFUser.query()!
Nathannn
  • 161
  • 4
  • 16