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

时间:2015-08-31 23:09:45

标签: ios objective-c swift uicollectionview jsqmessagesviewcontroller

我想根据enter link description here中提到的文档修改单元格UI,但无法确定如何翻译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!
}

1 个答案:

答案 0 :(得分:2)

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

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