How to add custom view to JSQMessagesViewController cell so that it includes one view with some buttons and text view?

前端 未结 1 1505
囚心锁ツ
囚心锁ツ 2021-01-07 02:56

I am using https://github.com/jessesquires/JSQMessagesViewController/issues/1820 this library for chat application. By using this libary I am able to send images and video,

相关标签:
1条回答
  • 2021-01-07 03:21

    I would suggest that you create your own custom view for this. You can use the JSQIncomingCollectionViewCell.xib or JSQOutgoingCollectionViewCell.xib as a template for your self.

    1. Copy them from the example project and paste them into your own
    2. Rename the files to something else like CellWithConfimationButtons
    3. In your ChatViewController i.e. what ever you called the view that is a subclass of 'JSQMessagesViewController'. Add these two lines

      self.collectionView.registerNib(UINib(nibName: "CellWithConfimationButtons", bundle: nil), forCellWithReuseIdentifier: "incomingCell") self.collectionView.registerNib(UINib(nibName: "CellWithConfimationButtons", bundle: nil), forCellWithReuseIdentifier: "outgoingCell")

    4. Now you can add your buttons to the xib files

    5. Add Constraints so that it lays its self out right.

    6. Set your Images for those and then you need to make your files that support this guy. Just like JSQMessagesCollectionViewCellOutgoing.m and JSQMessagesCollectionViewCellOutgoing.h Then you need to add you IBOutlets for the buttons and add the actions and logic in that file

    Then you need to set a flag or some way of determining that the message is this type of message with buttons.

    1. Then in your collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath)

    you check for that flag and get your cell

    if message.flag == true let cell = collectionView.dequeableCellWithIdentifier("incomingCell")

    Then set everything up.

    I hope that helps. let me know if I can help more.

    0 讨论(0)
提交回复
热议问题