2015-01-27 32 views
1

我試圖開發一個基於分析的排序社交網絡,並且遇到了試圖爲每個「組」創建投票系統的問題。在我的TableViewController中,使用PFQueryTableViewController,我收到錯誤「Use of unresolved identifier'object'」。這裏是我工作的部分使用未解析的標識符'object'Xcode 6 Swift

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


    group:PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject 
    cell.groupTextView.alpha = 0 
    cell.timeStampLabel.alpha = 0 
    cell.UserNameLabel.alpha = 0 

    cell.groupTextView.text = group.objectForKey("content") as String 

    var dataFormatter:NSDateFormatter = NSDateFormatter() 
    dataFormatter.dateFormat = "MM/DD/yyyy HH:mm" 
    cell.timeStampLabel.text = dataFormatter.stringFromDate(group.createdAt) 
    let score = object.valueForKey("count") as? Int 
    cell.count.text = "\(score)" 
    cell.groupTextView.text = object.valueForKey("content") as? String 
    var findUser:PFQuery = PFUser.query() 

    findUser.whereKey("objectId", equalTo: group.objectForKey("User").objectId) 

    findUser.findObjectsInBackgroundWithBlock { 
     (objects:[AnyObject]!, error:NSError!)->Void in 
     if error == nil{ 

      let user:PFUser = (objects as NSArray).lastObject as PFUser 
      cell.UserNameLabel.text = user.username 

      UIView.animateWithDuration(0.5, animations: { 
       cell.groupTextView.alpha = 1 
       cell.timeStampLabel.alpha = 1 
       cell.UserNameLabel.alpha = 1 

如果有人知道這裏的問題是什麼,請幫助開發者的初學者。

添加另一種方法從評論的完整性和格式:

override func objectAtIndexPath(indexPath: NSIndexPath!) -> PFObject! { 
    var object : PFObject? = nil 
    if(indexPath.row < self.objects.count) { 
     object = self.objects[indexPath.row] as? PFObject 
    } 
    return object 
} 
+0

哪一行會導致錯誤,並且該行的'object'聲明在哪裏? – 2015-01-27 00:36:54

回答

0

行: let score = object.valueForKey("count") as? Int

使用object,是它宣稱在那裏,並設置?

看來object被宣告爲另一個方法中的局部變量的廣告集,因此對於調用函數來說是未知的。

最佳猜測是object應該聲明爲類實例的屬性。

+0

在這個聲明之前,我有這個'重寫func objectAtIndexPath(indexPath:NSIndexPath!) - > PFObject! {var object:PFObject? = nil if(indexPath.row 2015-01-27 00:47:05

+0

這並不回答這個問題,'object'是該函數的局部變量。 – zaph 2015-01-27 01:32:32

0

有兩個類似的聲明

cell.groupTextView.text = group.objectForKey("content") as String 

而且

cell.groupTextView.text = object.valueForKey("content") as? String 

我相信第二個是從哪裏傳來的錯誤。刪除它,它應該是確定的。

相關問題