使用未解析的标识符'object'Xcode 6 Swift
我试图开发一个基于分析的排序社交网络,并且遇到了试图为每个“组”创建投票系统的问题。在我的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
}
行: let score = object.valueForKey("count") as? Int
使用object
,是它宣称在那里,并设置?
看来object
被宣告为另一个方法中的局部变量的广告集,因此对于调用函数来说是未知的。
最佳猜测是object
应该声明为类实例的属性。
在这个声明之前,我有这个'重写func objectAtIndexPath(indexPath:NSIndexPath!) - > PFObject! {var object:PFObject? = nil if(indexPath.row
这并不回答这个问题,'object'是该函数的局部变量。 – zaph 2015-01-27 01:32:32
有两个类似的声明
cell.groupTextView.text = group.objectForKey("content") as String
而且
cell.groupTextView.text = object.valueForKey("content") as? String
我相信第二个是从哪里传来的错误。删除它,它应该是确定的。
哪一行会导致错误,并且该行的'object'声明在哪里? – 2015-01-27 00:36:54