这是我第一次和Parse一起搬家。 Parse做了pod,我在Bridging-Hearder中导入了类,并声明了Delegate(swift)Id和我将使用的clientKey。让我怀疑,我必须做些什么来从Parse获取这些数据并将它们插入TableView?
答案 0 :(得分:3)
好的,你应该做的第一件事就是AppDelegate set id parse
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 }
我希望这有帮助!