2014-09-05 128 views
0

這是我第一次使用Parse移動。 Parse做了pod,我在Bridging-Hearder中導入了類,並聲明瞭Delegate(swift)Id和我將使用的clientKey。讓我懷疑,我必須做些什麼才能從Parse獲取這些數據並將它們插入到TableView中?快速解析(Tableview)

+0

解析iOS指南可以幫助你,因爲他們已經添加了沿着ObjC示例的swift代碼示例。 https://parse.com/docs/ios_guide – tsafrir 2014-09-05 14:53:26

回答

3

確定你應該做的第一件事就是在AppDelegate中集ID解析

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { 

    Parse.setApplicationId("ID-PARSE", clientKey: "KEY-PARSE") return true } 

創建一個對象

var message:PFObject = PFObject(className:"CLASS-NAME") 
    message["NAME ROW IN YOUR DATABASE PARSE"] = messageBox.text as String 
    message["User"] = PFUser.currentUser() 
    message.saveInBackground() 

負載數據解析

func loaddata() 
{ 
    var dataParse:NSMutableArray = NSMutableArray() 
    var findDataParse:PFQuery = PFQuery(className: "NAME ROW IN YOUR DATABASE PARSE") 

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

     if (!error){ 
      for object:PFObject! in objects 
      { 
       self.dataParse.addObject(object) 
      } 
     } 
     //// add data into array 
     let array:NSArray = self.dataParse.reverseObjectEnumerator().allObjects 
     self.dataParse = array as NSMutableArray 

     self.tableView.reloadData() 
    } 

} 
現在

override func numberOfSectionsInTableView(tableView: UITableView!) -> Int 
{ 
    return 1 
} 


override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int 
{ 
    return self.dataParse.count 
} 


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

    let cell:CustomCell = tableView!.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath!) as CustomCell 

    let cellDataParse:PFObject = self.dataParse.objectAtIndex(indexPath!.row) as PFObject 

    cell.mensajeBox.text = cellDataParse.objectForKey("NAME ROW IN YOUR DATABASE PARSE") as String return cell } 

我希望這可以幫到你!