我在设置Parse数据和UITableView时遇到问题。每次我运行应用程序时,无论是在模拟器上还是在手机上,应用程序都会停止工作,控制台只显示(lldb)
。在检查调试器时,只高亮显示以下两行代码。
findTimelineData.findObjectsInBackgroundWithBlock{
和
self.timelineData = array as NSMutableArray
两者都有错误:Thread 1: EXC_BREAKPOINT (code=EXC_I386_BPT,subcode=0x0)
和我不太确定这意味着什么。。。
以下是我的代码片段:
override func viewDidAppear(animated: Bool)
{
self.loadData()
}
func loadData()
{
timelineData.removeAllObjects()
var findTimelineData : PFQuery = PFUser.query()
findTimelineData.findObjectsInBackgroundWithBlock{
(objects: [AnyObject]!, error: NSError!)-> Void in
if error == nil
{
println("No error")
if let object = objects as? [PFObject!]
{
for object in objects
{
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
{
println("loading cell")
let postCell : LocationTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as LocationTableViewCell
let post : PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject
postCell.imageView.image = post.objectForKey("currentLocation") as? UIImage
postCell.userInfo.text = post.objectForKey("FirstLastName") as? String
// Configure the cell...
return postCell
}
完整代码:http://pastebin.com/MN7qcFhq
这对我有效:
在您的代码中只需替换
self.timelineData = array as NSMutableArray
至
self.timelineData = NSMutableArray(array: array)
你不是在中缺少一个s吗
if let object = objects as? [PFObject!]
{
for object in objects
{
self.timelineData.addObject(object)
}
}
应为:
if let objects = objects as? [PFObject!]
{
for object in objects
{
self.timelineData.addObject(object)
}
}
嘿,伙计,我帮你搞定了。我也有同样的问题,但我得到了帮助并解决了问题。
这是您的加载函数
试试这个
func loadData(){
timelineData.removeAll(keepCapacity: false)
var findTimelineData:PFQuery = PFQuery(className:"Sweets")
findTimelineData.findObjectsInBackgroundWithBlock
{
(objects:[AnyObject]! , error:NSError!) -> Void in
if error == nil
{
self.timelineData = objects.reverse() as [PFObject]
//let array:NSArray = self.timelineData.reverseObjectEnumerator().allObjects
println(objects)
// self.timelineData = array as NSMutableArray
self.tableView.reloadData()
}
}
}
然后转到
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
并更改
let sweet:PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject
到此
let sweet: PFObject = self.timelineData[indexPath.row] as PFObject
现在的情况是,你将一些Obj C与Swift混合在一起,你下面的代码可能是用Beta编写的,所以一定要回去了解其中的区别。如果您仍然有问题,请检查您的所有条件If(error!=nil)不应该出现在代码中。