Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this is in my parent view controller
- var scoutTableViewController:TableViewController = TableViewController(data: self.scenes!)
- scoutTableViewController.view.frame = CGRectMake(0.0, 54.0, self.view.frame.size.width, self.view.frame.size.height - 54 - 54)
- self.addChildViewController(scoutTableViewController)
- self.view.addSubview(scoutTableViewController.view)
- //this is the child tableviewcontroller
- init(data:SceneCollection){
- self.sceneCollection = data.models
- var aDecoder: NSCoder!
- super.init(coder: aDecoder)
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- NSNotificationCenter.defaultCenter().addObserverForName("sceneCollectionFetched",
- object: nil,
- queue: NSOperationQueue.mainQueue()) { _ in
- self.tableView.reloadData()
- }
- }
- //Here is the data
- class SceneCollection{
- var models:Array<SceneModel>
- init(){
- self.models = []
- }
- func fetchAllScenesNearUser(){
- //eventually add users location in call with location:CLLocation?, accuracy:CLLocationAccuracy?
- var query:PFQuery = PFQuery(className: "Scene")
- // temporary hardcoding gps location to get data
- let geolocation:PFGeoPoint = PFGeoPoint(latitude: 30.3, longitude: -97.7)
- query.whereKey("location", nearGeoPoint: geolocation, withinMiles: 400.0)
- query.includeKey("parseUserKey")
- query.findObjectsInBackgroundWithBlock({(PFObjectResultBlock, NSError) in
- for scene : AnyObject in PFObjectResultBlock {
- self.addSceneModel(scene as PFObject)
- }
- NSNotificationCenter.defaultCenter().postNotification(NSNotification(name: "sceneCollectionFetched", object: nil))
- })
- }
- func addSceneModel(scene:PFObject){
- self.models += SceneModel(scene:scene)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement