Skip to content

Instantly share code, notes, and snippets.

@Katafalkas
Created December 11, 2014 22:15
Show Gist options
  • Save Katafalkas/8336d283a5ccc84a4ec4 to your computer and use it in GitHub Desktop.
Save Katafalkas/8336d283a5ccc84a4ec4 to your computer and use it in GitHub Desktop.
JSQMessagesViewController for Swift
import UIKit
class MsgVC: JSQMessagesViewController {
var msg:JSQMessage!
var outBubble:JSQMessageBubbleImageDataSource!
override func viewDidLoad() {
initThisView()
self.outBubble = JSQMessagesBubbleImageFactory().outgoingMessagesBubbleImageWithColor(UIColor.jsq_messageBubbleBlueColor())
}
func initThisView() {
self.view.backgroundColor = UIColor.whiteColor()
self.msg = JSQMessage(senderId: "SuperUniqId", senderDisplayName: "SomeName", date: NSDate(), text: "Ichy, Knee, San, Chee, Go !..")
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
// let cell = super.collectionView(collectionView, cellForItemAtIndexPath: indexPath) as JSQMessagesCollectionViewCell
let cell = JSQMessagesCollectionViewCell(frame: CGRectMake(0.0, 0.0, 100.0, 100.0))
cell.textView.text = self.msg.text
return cell
}
}
extension MsgVC: JSQMessagesCollectionViewDataSource {
func senderDisplayName() -> String! {
return "SomeName"
}
func senderId() -> String! {
return "123"
}
override func collectionView(collectionView: JSQMessagesCollectionView!, messageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageData! {
return self.msg
}
override func collectionView(collectionView: JSQMessagesCollectionView!, messageBubbleImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageBubbleImageDataSource! {
return self.outBubble
}
override func collectionView(collectionView: JSQMessagesCollectionView!, avatarImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageAvatarImageDataSource! {
return nil
}
}
extension MsgVC: JSQMessagesCollectionViewDelegateFlowLayout {
}
@SamuraiT
Copy link

SamuraiT commented Mar 5, 2015

HI, @Katafalkas
this is great code but didnt work well.
I installed JSQMessagesViewController by pod. and just copied and pated this code and seted up this to viewcontroller. However, it didn't work well.
what can be the problem.
There was no error. but just default screen came.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment