首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从解析中将数据加载到TableView中

从解析中将数据加载到TableView中
EN

Stack Overflow用户
提问于 2015-11-15 14:59:40
回答 1查看 154关注 0票数 0

嗨,伙计们,我创建了一个函数,它下面是将项保存到tweetData : PFObject数组中的函数

代码语言:javascript
复制
 func loadData() {

    //all current data to be displayed, adding data 1 by 1 remove whats there on reloading
    tweetData.removeAll()

    //query database for all tweets, very important that whats in the classname here, is the
    //same name as the class with Parse where these are being stored

    let findTweets:PFQuery = PFQuery(className: "Tweets")

    findTweets.findObjectsInBackgroundWithBlock { (objects:[PFObject]?, error: NSError?) -> Void in

        if error == nil {

            for object:PFObject in objects! {

                self.tweetData.append(object)

            }

            //--very important!!! dont forget to reload table data otherwise you will return no results
            self.tableView.reloadData()

        } else {

            print("nothing to load")

        }

    }

}

我怎样才能把它放到我的桌面视图中来显示数据呢?一直在挣扎,并得到了各种各样的错误。这是我的表视图cellForRowAtIndexPath

代码语言:javascript
复制
 func tableView(tableView: UITableView, cellForRowAtIndexPath  

 indexPath: NSIndexPath) -> UITableViewCell {

    //use your custom table view cell here which is defined in another class

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


  //NEED TO LOAD MY DATA



    return cell

    //-----add load data function to viewDidAppear method


}

有人能帮我吗?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-15 15:15:18

代码语言:javascript
复制
all sorted just used query.objectforkey


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

    //use your custom table view cell here which is defined in another class

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

    let query = tweetData[indexPath.row]

    cell.textLabel!.text = query.objectForKey("TweetContent") as? String

    return cell

    //-----add load data function to viewDidAppear method


}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33721118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档