分析后端和Swift UITableview

分析后端和Swift UITableview,uitableview,swift,parse-platform,Uitableview,Swift,Parse Platform,我试图弄清楚如何在UITableView中通过解析后端显示查询 func retrieveParse(){ var query:PFQuery = PFQuery(className:"Noticias") query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]!, error: NSError!) -> Void in if error == nil { for object:PFO

我试图弄清楚如何在UITableView中通过解析后端显示查询

func retrieveParse(){
var query:PFQuery = PFQuery(className:"Noticias")

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

    if error == nil {
        for object:PFObject! in objects as [PFObject] {
            self.timelineData.addObject(object)
        }

        let array:NSArray =       self.timelineData.reverseObjectEnumerator().allObjects
        self.timelineData = array as NSMutableArray

        self.tableView.reloadData()
    }
}

}//

override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell:CellTableViewCell = tableView!.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as CellTableViewCell

// Configure the cell...

    let sweet:PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject

    cell.tituloLabel = sweet.objectForKey("sobre") as UILabel

return cell
}
我已经阅读了文档,并成功地在ViewController中的标签上显示了一些查询,但在TableView中显示结果时遇到了麻烦

func retrieveParse(){
var query:PFQuery = PFQuery(className:"Noticias")

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

    if error == nil {
        for object:PFObject! in objects as [PFObject] {
            self.timelineData.addObject(object)
        }

        let array:NSArray =       self.timelineData.reverseObjectEnumerator().allObjects
        self.timelineData = array as NSMutableArray

        self.tableView.reloadData()
    }
}

}//

override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell:CellTableViewCell = tableView!.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as CellTableViewCell

// Configure the cell...

    let sweet:PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject

    cell.tituloLabel = sweet.objectForKey("sobre") as UILabel

return cell
}
我是一个尝试用swift编程的新手

基本上,我在UITableView中有这个函数

func retrieveParse(){
var query:PFQuery = PFQuery(className:"Noticias")

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

    if error == nil {
        for object:PFObject! in objects as [PFObject] {
            self.timelineData.addObject(object)
        }

        let array:NSArray =       self.timelineData.reverseObjectEnumerator().allObjects
        self.timelineData = array as NSMutableArray

        self.tableView.reloadData()
    }
}

}//

override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell:CellTableViewCell = tableView!.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as CellTableViewCell

// Configure the cell...

    let sweet:PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject

    cell.tituloLabel = sweet.objectForKey("sobre") as UILabel

return cell
}
我只想在UILabel中显示一些信息,我不知道我的func是否正确,但当我尝试运行代码时,我收到一个错误:

0x112682662: nopw %cs:(%rax,%rax) Thread 1:EXC_BREAKPOINT (code=EXC_l386_BPT, subcode=0x0)

我建议大家看看parse.com的例子:


您需要实现PFQueryTableViewController。并重写queryForTable方法。由于parse.com的数据是异步的,所以我认为您的问题就来自于此

我确信这句话是不对的:

cell.tituloLabel = sweet.objectForKey("sobre") as UILabel
我不认为sobre属性是UILabel。尝试将cell.titullabel.text设置为sweet.objectForKeysobre


由于我们没有看到代码的其余部分,我假设您没有忘记实现func tableview tableview:UITableView,numberofrowsinssection:Int->Int?

使用简单字符串创建表,添加一些日志记录,然后,如果简单表工作,添加PFObject部分。把它分解,找出问题所在,isI也会喜欢swift中的一个例子。我已经为此挣扎了一段时间。谢谢你对斯威夫特的看法是什么?例如,您能否在github中提供完整的代码以了解问题所在?我已经实现了目标C,没有任何问题。