Skip to content

messageInputBar.delegate = self does not work  #33

@taigaisatiger

Description

@taigaisatiger

I am trying to trying to implement a chat feature in my app but it is not going so well.
I was trying to check if the send button was working correctly by printing out "button is pushed", but it didn't get printed.
I realized messageInputBar.delegate = self was not in the code and I thought that was the problem and as I put in the line of code an error below popped up. I don't know how to fix this and it would be a great help if you could give me an advice on what I should do.
Cannot assign value of type 'MessageKitChatViewController' to type 'InputBarAccessoryViewDelegate?' Add missing conformance to 'InputBarAccessoryViewDelegate' to class 'MessageKitChatViewController'

`import UIKit
import MessageKit
import MessageInputBar
import FirebaseFirestore
import FirebaseAuth
import FirebaseStorage
import Nuke

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

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

class MessageKitChatViewController: MessagesViewController, MessagesDataSource, MessagesLayoutDelegate, MessagesDisplayDelegate, MessageInputBarDelegate{

var senderUser = Auth.auth().currentUser!
var messages = [MessageType]()

let currentUser = Sender(senderId: Auth.auth().currentUser!.uid , displayName: Auth.auth().currentUser!.displayName ??  "Name not found")



override func viewDidLoad() {
    super.viewDidLoad()
    messagesCollectionView.messagesDataSource = self
    messagesCollectionView.messagesLayoutDelegate = self
    messagesCollectionView.messagesDisplayDelegate = self
    messageInputBar.delegate = self
}

func currentSender() -> 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
}


func messageInputBar(_ inputBar: MessageInputBar, didPressSendButtonWith text: String) {

// let message = MessageKitMessage(sender: currentUser, messageId: UUID().uuidString, sentDate: Timestamp().dateValue(), kind: .text(text))
print("button is pushed")
}

}

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions