我在设置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
答案 0 :(得分:1)
这对我有用:
代码中的只是替换
self.timelineData = array as NSMutableArray
到
self.timelineData = NSMutableArray(array: array)
答案 1 :(得分:0)
Aren你错过了一个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)
}
}
答案 2 :(得分:0)
嘿伙计我帮你了。我遇到了同样的问题,但我得到了帮助并弄明白了。
这是您的加载功能
试试这个
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编写的,所以一定要回去学习它们。如果您仍然遇到问题,请检查所有条件,如果(错误!= nil)不在您的代码中。