本文介绍了如何将自定义视图添加到JSQMessagesViewController单元格,以便它包含一个带有一些按钮和文本视图的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用



以下是我想要自定义视图的屏幕截图。它有一些文本用户输入并有2个接受和拒绝按钮。

解决方案

我建议您创建自己的自定义鉴于此。您可以使用 JSQIncomingCollectionViewCell.xib JSQOutgoingCollectionViewCell.xib 作为自己的模板。


  1. 从示例项目中复制它们并将它们粘贴到您自己的

  2. 将文件重命名为某些内容否则像 CellWithConfimationButtons

  3. 在你的ChatViewController中,即你所谓的视图是'JSQMessagesViewController'的子类。添加这两行



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


  4. 现在你可以将你的按钮添加到xib文件


  5. 添加约束以使其自行向右。


  6. 为那些设置图像,然后你需要制作支持这个人的文件。就像 JSQMessagesCollectionViewCellOutgoing.m JSQMessagesCollectionViewCellOutgoing.h 然后你需要添加 IBOutlets 用于按钮并在该文件中添加操作和逻辑


然后你需要设置一个标记或某种方式确定消息是带有按钮的此类消息。


  1. 然后在您的 collectionView(collectionView:UICollectionView,cellForItemAtIndexPath indexPath:NSIndexPath)

你检查那个标志和获取你的手机



如果message.flag == true,请让cell = collectionView.dequeableCellWithIdentifier(incomingCell)



然后设置一切。



我希望有所帮助。让我知道我是否可以提供更多帮助。

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, but my app needs to send one view with some button and text. Like when user sends some text it will appear to others as text and button and then when somebody clicks the button one push notification will be generated. I am not able to figure it out how can I achieve this.

Here is screen shot how I want my custom view to be. It has some text user has typed and has 2 button for accept and reject.

解决方案

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.

这篇关于如何将自定义视图添加到JSQMessagesViewController单元格,以便它包含一个带有一些按钮和文本视图的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 22:12