我在 XCode 6 中遇到一个有趣的错误:
UICollectionView 没有名为 dequeueResuableCellWithReuseIdentifier 的成员
错误出现在以下函数的第二行(“let cell...”):
override func collectionView(collectionView: UICollectionView?, cellForItemAtIndexPath indexPath: NSIndexPath?) -> UICollectionViewCell {
// Configure the cell
let cell:FightCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as FightCollectionViewCell
let battle = self.lobbyData.objectAtIndex(indexPath!.row) as PFUser
PFCloud.callFunctionInBackground("getOnlineUsers", withParameters: [:], target: nil, selector: "block:")
func block(users: NSArray, error:NSError!){
if(error == nil){
let user:PFUser = (users as NSArray).lastObject as PFUser
let avatarObject = user["avatar"] as PFObject!
avatarObject.fetchInBackgroundWithBlock {
(object: PFObject!, error: NSError!) in
if error == nil {
let imageFile = object["image"] as PFFile
imageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
if error == nil {
let image = UIImage(data:imageData)
cell.avatarImageView.image = image
}
}
}
}
}
}
return cell
}
这段代码在 XCode 6 beta 中没有抛出错误。为什么 XCode 现在对那行代码有问题?我是 iOS 开发的新手,所以非常感谢任何帮助。
谢谢!
最佳答案
根据您的方法签名,我猜您的错误消息是真的 UICollectionView?没有名为 dequeueResuableCellWithReuseIdentifier 的成员
。
UICollectionView?
是与 UICollectionView
完全不同的类型。这是一个optional ,并且它绝对没有定义与 UICollectionView
相同的方法!
查看the API ,该委托(delegate)方法未定义为采用可选值。尝试删除 ?
。
原因是整个 Cocoa API(数量巨大)必须手动检查可选的一致性,这仍然是一个持续的过程。这会导致 Xcode 版本之间的 API 更改。
关于ios - UICollectionView 没有名为 dequeueResuableCellWithReuseIdentifier 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26457098/