cellForItemAtIndexPath

cellForItemAtIndexPath

我想根据这里提到的enter link description here文档修改cell 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!
}

最佳答案

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

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

10-08 09:14