ios - 如何将 Objective-C 中的这段代码翻译成 Swift

标签 ios objective-c swift uicollectionview jsqmessagesviewcontroller

我想根据此处提到的文档修改单元格用户界面 enter link description here , 但不知道如何翻译 super 部分。

- (UICollectionViewCell *)collectionView:(JSQMessagesCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    JSQMessagesCollectionViewCell *cell = (JSQMessagesCollectionViewCell *)[super collectionView:collectionView cellForItemAtIndexPath:indexPath];

    return cell;
}

这是我翻译的内容:

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    var cell = super.collectionView.cellForItemAtIndexPath(indexPath)

    return cell!
}

最佳答案

如果您正在寻找正确的语法,这里是解决方案:

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
      let cell = super.collectionView(collectionView, cellForItemAtIndexPath: indexPath) as! JSQMessagesCollectionViewCell
      return cell
}

关于ios - 如何将 Objective-C 中的这段代码翻译成 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32321254/

相关文章:

ios - Xamarin 表格 : CustomWebView on iOS didn't show a simple webpage

ios - 分段控制切换多个表格 View

ios - 无法从 for 循环调用方法

objective-c - 使用 Objective-C 的 Mac OS X 守护进程 - launchd

swift - 如何在 RealityKit 中隐藏 ModelEntity?

swift - 从核心数据中删除项目

ios - C# 规范是否允许从 ulong 转换为 int? Monotouch 给出一个 NumberOverflow

ios - Metal Device (MTLDevice) 变量在初始化后变为 nil

ios - 在 iTunes 连接中出现错误

ios - 有没有办法获取我的 iOS 应用程序屏幕截图列表?