2014-11-08 42 views
0

我有解析數據和UITableView設置問題。每次運行該應用程序時,無論是在模擬器還是手機上,應用程序都停止工作,控制檯顯示的唯一信息是(lldb)。在檢查調試器時,只會突出顯示兩行代碼。UITableView和解析數據

findTimelineData.findObjectsInBackgroundWithBlock{ 

self.timelineData = array as NSMutableArray 

雙方都有錯誤:Thread 1: EXC_BREAKPOINT (code=EXC_I386_BPT,subcode=0x0)和IM不太清楚這是什麼意思?

這裏是我的代碼片段:

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

你不是在缺少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) 
    } 
} 
+0

只是去嘗試,只有錯誤改變了..我仍然得到一個錯誤,除了這一次,錯誤是:'線程1:EXC_BREAKPOINT(代碼= EXC_ARM_BREAKPOINT,子代碼= 0xdefe)' – gguillaume 2014-11-08 16:19:16

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編寫的,因此請確保您返回並瞭解差異。如果你仍然有問題,如果(錯誤!=零)不應該在你的代碼中檢查你的所有條件。

1

這個工作對我來說:

在你的代碼

僅僅只有更換

self.timelineData = array as NSMutableArray 

self.timelineData = NSMutableArray(array: array)