Created
December 11, 2014 22:15
-
-
Save Katafalkas/8336d283a5ccc84a4ec4 to your computer and use it in GitHub Desktop.
JSQMessagesViewController for Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.