问题
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.
回答1:
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.
- Copy them from the example project and paste them into your own
- Rename the files to something else like
CellWithConfimationButtons
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")
Now you can add your buttons to the xib files
Add Constraints so that it lays its self out right.
Set your Images for those and then you need to make your files that support this guy. Just like
JSQMessagesCollectionViewCellOutgoing.m
andJSQMessagesCollectionViewCellOutgoing.h
Then you need to add youIBOutlets
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.
- 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. 😜
来源:https://stackoverflow.com/questions/39373082/how-to-add-custom-view-to-jsqmessagesviewcontroller-cell-so-that-it-includes-one