ios - UICollectionView 没有名为 dequeueResuableCellWithReuseIdentifier 的成员

标签 ios xcode swift uicollectionview

我在 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/

相关文章:

ios - CISpotLight 过滤器和零结果

ios - UICollectionViewCell 中的 UICollectionView 滚动缓慢/滞后

arrays - joined() 还是 flatMap(_ :) perform better in Swift 3?

ios - 在本地化字符串中使用变量

ios - Swift 4 - swift 中带有两个圆角的 ImageView ?

objective-c - 以编程方式手动链接 XIB 中声明的 UIButton 和 VIewController 中的属性

ios - 当幻灯片拖动时,如何在动态表格 View 单元格的标签上显示幻灯片的当前值?

c++ - C++ 静态类 : undefined symbols 的 Clang 链接错误

ios - Xcode 中的图像大小是否需要正好是 1x/2x/3x 比例?

ios - 如何使 Core Plot 显示每个时间点的 x 轴标签?