3

ユーザーがメッセージ バブルをタップしたときにアクションを実行するハンドラーを挿入する方法を理解しようとしています。「セルのカスタマイズ」に関する readme のセクションを見つけて、いくつかの異なるアプローチを試しましたが、今のところうまくいきません。これが私が試したことです:

実装:

- (void)collectionView:(JSQMessagesCollectionView *)collectionView didTapMessageBubbleAtIndexPath:(NSIndexPath *)indexPath

私のviewControllerように:

override func collectionView(collectionView: JSQMessagesCollectionView, didTapMessageBubbleAtIndexPath indexPath: NSIndexPath!) {
    super.collectionView(collectionView, didTapMessageBubbleAtIndexPath: indexPath)
    println("They tapped!")
}

ただし、これは何らかの理由でまったく呼び出されないようです。

私が試した他のことは実装です:

- (UICollectionViewCell *)collectionView:(JSQMessagesCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

私のView Controllerでは:

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

    let myDelegate = MyJSQMessagesCollectionViewCellDelegate(origDelegate: cell.delegate!)
    cell.delegate = myDelegate

    return cell;
}

これは呼び出されますが、デリゲートのメソッドは呼び出されません。

JSQMessagesCollectionViewCellDelegateそれで、それが呼び出されるように適切に配置する方法についての提案はありますか? または、メソッドをオーバーライドする最初の試みdidTapMessageBubbleAtIndexPathは適切な方法ですか?

任意の提案をいただければ幸いです。

4

1 に答える 1

2

わかりました。自分のデリゲートを挿入しようとすると、実際には問題が発生しました (私がやろうとしたことを達成できなかったことに加えて)。「cellForItemAtIndexPath」メソッドを削除すると、「didTapMessageBubbleAtIndexPath」が起動し始めました。

于 2015-09-06T18:03:01.507 に答える