Advertisement
Guest User

Untitled

a guest
Jul 10th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1.  
  2. //this is in my parent view controller
  3. var scoutTableViewController:TableViewController = TableViewController(data: self.scenes!)
  4. scoutTableViewController.view.frame = CGRectMake(0.0, 54.0, self.view.frame.size.width, self.view.frame.size.height - 54 - 54)
  5. self.addChildViewController(scoutTableViewController)
  6. self.view.addSubview(scoutTableViewController.view)
  7.  
  8.  
  9.  
  10. //this is the child tableviewcontroller
  11. init(data:SceneCollection){
  12. self.sceneCollection = data.models
  13. var aDecoder: NSCoder!
  14. super.init(coder: aDecoder)
  15. }
  16.  
  17. override func viewDidLoad() {
  18. super.viewDidLoad()
  19. NSNotificationCenter.defaultCenter().addObserverForName("sceneCollectionFetched",
  20. object: nil,
  21. queue: NSOperationQueue.mainQueue()) { _ in
  22. self.tableView.reloadData()
  23. }
  24. }
  25.  
  26.  
  27. //Here is the data
  28.  
  29. class SceneCollection{
  30.  
  31. var models:Array<SceneModel>
  32.  
  33. init(){
  34. self.models = []
  35. }
  36.  
  37. func fetchAllScenesNearUser(){
  38. //eventually add users location in call with location:CLLocation?, accuracy:CLLocationAccuracy?
  39. var query:PFQuery = PFQuery(className: "Scene")
  40.  
  41. // temporary hardcoding gps location to get data
  42. let geolocation:PFGeoPoint = PFGeoPoint(latitude: 30.3, longitude: -97.7)
  43. query.whereKey("location", nearGeoPoint: geolocation, withinMiles: 400.0)
  44. query.includeKey("parseUserKey")
  45. query.findObjectsInBackgroundWithBlock({(PFObjectResultBlock, NSError) in
  46. for scene : AnyObject in PFObjectResultBlock {
  47. self.addSceneModel(scene as PFObject)
  48. }
  49. NSNotificationCenter.defaultCenter().postNotification(NSNotification(name: "sceneCollectionFetched", object: nil))
  50. })
  51.  
  52. }
  53.  
  54. func addSceneModel(scene:PFObject){
  55. self.models += SceneModel(scene:scene)
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement