Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text bubbles do not appear! #1835

Open
Noah-Ksk opened this issue Mar 23, 2024 · 1 comment
Open

Text bubbles do not appear! #1835

Noah-Ksk opened this issue Mar 23, 2024 · 1 comment
Labels

Comments

@Noah-Ksk
Copy link

Hi. I want to use messageKit to implement a chat section in my app. I set the interface like this below but when I pushed textingVc I can not see the text bubbles. I can monitor the other properties like textbar and send button etc. Here is my code block

`
import UIKit
import MessageKit

struct Sender : SenderType {
var senderId: String
var displayName: String
}

struct Message : MessageType {
var sender: SenderType
var messageId: String
var sentDate: Date
var kind: MessageKind
}

struct Media: MediaItem {
var url: URL?

var image: UIImage?

var placeholderImage: UIImage

var size: CGSize

}

class TextingVC: MessagesViewController, MessagesDataSource, MessagesLayoutDelegate, MessagesDisplayDelegate, MessageLabelDelegate {
var currentSender: SenderType = Sender(senderId: "self", displayName: "Noah")

/*var currentSender: SenderType {
    return Sender(senderId: "self", displayName: "Noah")
}*/
var otherSender: SenderType {
    return Sender(senderId: "other", displayName: "Unknown")
}
var messages : [Message] = []

override func viewDidLoad() {
    super.viewDidLoad()
    
    
    messages.append(Message(sender: currentSender,
                            messageId: "1",
                            sentDate: Date(),
                            kind: .photo(Media(url: nil, image: UIImage(named: "ikon"), placeholderImage: UIImage(named: "ikon")!, size: CGSizeMake(200, 200)))))
    messages.append(Message(sender: otherSender,
                            messageId: "2",
                            sentDate: Date(),
                            kind: .text("Some examples here")))
    messages.append(Message(sender: currentSender,
                            messageId: "3",
                            sentDate: Date(),
                            kind: .text("Its gonna work?")))
    messages.append(Message(sender: otherSender,
                            messageId: "4",
                            sentDate: Date(),
                            kind: .text("some words !")))
    messages.append(Message(sender: currentSender,
                            messageId: "5",
                            sentDate: Date(),
                            kind: .text("finally")))
    
    messagesCollectionView.messagesDataSource = self
    messagesCollectionView.messagesLayoutDelegate = self
    messagesCollectionView.messagesDisplayDelegate = self
    
}
func textColor(for message: any MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UIColor {
    return .red
}


func messageForItem(at indexPath: IndexPath, in messagesCollectionView: MessageKit.MessagesCollectionView) -> any MessageKit.MessageType {
    return messages[indexPath.section]
}

func numberOfSections(in messagesCollectionView: MessageKit.MessagesCollectionView) -> Int {
    return messages.count
}

}`

Xcode version 15.3
similator ios 17.2 15 Pro
messageKit 4.2.0

@hidoon
Copy link

hidoon commented Apr 4, 2024

you forgot to refresh the collection view:
messagesCollectionView.reloadData()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants