解析后端和Swift UITableview

问题描述:

我想弄清楚如何通过解析后端在UITableView中显示查询。解析后端和Swift UITableview

我读过文档,并且成功可以在ViewController的标签上显示一些查询,但是我有麻烦在TableView中显示结果。

我与迅速

新手试图编程基本上,我有我的UITableView这里面FUNC。

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) 
+0

使表格以简单的字符串工作,添加一些日志记录,然后,如果简单表格工作,添加PFObject部分。把它分解出来,找出问题所在 – Wain 2015-02-09 13:38:03

我建议看看parse.com示例: https://parse.com/tutorials/anypic

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

+0

我也很喜欢swift中的一个例子。我一直在努力。谢谢! – 2015-02-09 14:20:19

+0

这是你的Swift问题吗?你能提供完整的代码(例如在github中)来了解什么是问题? 我用Objective C实现了这个,没有任何问题。 – 2015-02-10 05:18:09

我敢确信,这条线是不正确的:

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

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

由于我们没有看到您的其他代码,我假设您没有忘记实施func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int