我试着让项目尽可能简单,因为我想我忘记了一些东西,但我不知道是什么,我挣扎了2个小时...
正如您在屏幕上看到的:视图是载入的,除了这消息.请在这里找到我的代码:
import UIKit
import MessageKit
struct Sender: SenderType {
var senderId: String
var displayName: String
}
struct Message: MessageType {
var sender: MessageKit.SenderType
var messageId: String
var sentDate: Date
var kind: MessageKit.MessageKind
}
class ViewController: MessagesViewController {
var messages = [Message]()
let currentUser = Sender(senderId: "myId", displayName: "Mark")
override func viewDidLoad() {
super.viewDidLoad()
messagesCollectionView.messagesDataSource = self
messagesCollectionView.messagesLayoutDelegate = self
messagesCollectionView.messagesDisplayDelegate = self
messages.append(Message(sender: currentUser, messageId: "123", sentDate: Date().addingTimeInterval(-86400) , kind: .text("Hey Vivaan, You are going to influence")))
messages.append(Message(sender: currentUser, messageId: "143", sentDate: Date().addingTimeInterval(-86405) , kind: .text("Hey Vivaan, You are going to influence")))
messages.append(Message(sender: currentUser, messageId: "153", sentDate: Date().addingTimeInterval(-86404) , kind: .text("Hey Vivaan, You are going to influence")))
messages.append(Message(sender: currentUser, messageId: "163", sentDate: Date().addingTimeInterval(-86403) , kind: .text("Hey Vivaan, You are going to influence")))
}
}
extension ViewController: MessagesDataSource {
var currentSender: MessageKit.SenderType {
return currentUser
}
func messageForItem(at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> MessageType {
return messages[indexPath.section]
}
func numberOfSections(in messagesCollectionView: MessagesCollectionView) -> Int {
return messages.count
}
}
extension ViewController: MessagesDisplayDelegate, MessagesLayoutDelegate { }
我确实读了所有的文档,并看了一些例子。对我来说似乎还可以。
谢谢你的帮忙
app picture
1条答案
按热度按时间j9per5c41#
这帮助了我
在viewDidload中创建并粘贴此函数