【问题标题】:Parse using in swift (Tableview)在 swift (Tableview) 中使用解析
【发布时间】:2014-09-05 13:54:25
【问题描述】:

这是我第一次使用 Parse。 Parse 做了 pod,我在 Bridging-Hearder 中导入了类,并声明了我将使用的 Id 和 clientKey 的委托(swift)。让我怀疑一下,我必须做什么才能从 Parse 获取这些数据并将它们插入 TableView?

【问题讨论】:

  • Parse iOS 指南可以为您提供很大帮助,因为他们已经在 ObjC 示例中添加了快速代码示例。 parse.com/docs/ios_guide

标签: swift parse-platform


【解决方案1】:

好的,你应该做的第一件事是在 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 }

我希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多