Skip to content

keep getting message input bar delegate ambiguous for type lookup in this context #27

@lordKaos11

Description

@lordKaos11

import UIKit
import MessageKit
import MessageInputBar

class newViewController: MessagesViewController {

var messages: [Message] = []
var member: Member!

override func viewDidLoad() {
    super.viewDidLoad()
    member = Member(name: "bluemoon", color: .blue)
    messagesCollectionView.messagesDataSource = self
    messagesCollectionView.messagesLayoutDelegate = self
    messagesCollectionView.messagesDisplayDelegate = self
    messagesCollectionView.messageCellDelegate = self as? MessageCellDelegate
    // Do any additional setup after loading the view.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destination.
    // Pass the selected object to the new view controller.
}
*/

}

extension newViewController: MessagesDataSource {
func currentSender() -> SenderType {
return Sender(id: member.name, displayName: member.name)

}

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


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

func messageTopLabelHeight(
    for message: MessageType,
    at indexPath: IndexPath,
    in messagesCollectionView: MessagesCollectionView) -> CGFloat {
    
    return 12
}

func messageTopLabelAttributedText(
    for message: MessageType,
    at indexPath: IndexPath) -> NSAttributedString? {
    
    return NSAttributedString(
        string: message.sender.displayName,
        attributes: [.font: UIFont.systemFont(ofSize: 12)])
}

}

extension newViewController: MessagesLayoutDelegate {
func heightForLocation(message: MessageType,
at indexPath: IndexPath,
with maxWidth: CGFloat,
in messagesCollectionView: MessagesCollectionView) -> CGFloat {

    return 0
}

}

extension newViewController: MessagesDisplayDelegate {
func configureAvatarView(
_ avatarView: AvatarView,
for message: MessageType,
at indexPath: IndexPath,
in messagesCollectionView: MessagesCollectionView) {

    let message = messages[indexPath.section]
    let color = message.member.color
    avatarView.backgroundColor = color
}

}

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

    let newMessage = Message(
        member: member,
        text: text,
        messageId: UUID().uuidString)
    
    messages.append(newMessage)
    inputBar.inputTextView.text = ""
    messagesCollectionView.reloadData()
    messagesCollectionView.scrollToBottom(animated: true)
}

}

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