Нажмите конкретный AccessoryView в MessageKit - PullRequest
1 голос
/ 08 марта 2019

У меня есть вопрос по MessageKit.Как мы могли указать конкретную ячейку чата, чтобы при нажатии на didTapAccessoryView(in cell:) мы получали индекс этого accessoryView.Мне нужен индекс, чтобы ввести некоторую информацию, прежде чем показывать новый VC.Это вообще возможно или я трачу время на MessageCellDelegate.

// MARK: - MessageCellDelegate
extension ChatVC:MessageCellDelegate{
    func didTapAvatar(in cell: MessageCollectionViewCell) {
        print("Avatar tapped")
    }

    func didTapMessage(in cell: MessageCollectionViewCell) {
        print("Message tapped")
    }

    func didTapCellTopLabel(in cell: MessageCollectionViewCell) {
        print("Top cell label tapped")
    }

    func didTapMessageTopLabel(in cell: MessageCollectionViewCell) {
        print("Top message label tapped")
    }

    func didTapMessageBottomLabel(in cell: MessageCollectionViewCell) {
        print("Bottom label tapped")
    }

    func didTapAccessoryView(in cell: MessageCollectionViewCell) {
        let chatChallengeVC = DIConfigurator.sharedInst().getChatChallengeVC() 
        self.navigationController?.show(chatChallengeVC, sender: nil)
    }
}

Я пытался добавить цель к кнопке, как показано ниже:

    func configureAccessoryView(_ accessoryView: UIView, for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) {
        // Cells are reused, so only add a button here once. For real use you would need to
        // ensure any subviews are removed if not needed
        switch(message.kind){
            case .photo(_):
                guard accessoryView.subviews.isEmpty else { return }
                accessoryView.isUserInteractionEnabled = true
                accessoryView.target(forAction: #selector(tapped), withSender: nil)
                let button = UIButton(type: .infoLight)
                button.tintColor = .primaryChatColor
                accessoryView.addSubview(button)
                button.frame = accessoryView.bounds
                button.isUserInteractionEnabled = true

                // Like this
                button.target(forAction: #selector(tapped(sender:)), withSender: self)
                accessoryView.layer.cornerRadius = accessoryView.frame.height / 2
                accessoryView.backgroundColor = UIColor.primaryChatColor.withAlphaComponent(0.3)
            default:
                log.info("Default value")
        }
    }

Кнопка не является интерактивной, и didTapAccessoryView(in cell: MessageCollectionViewCell) вызывается, когда я выполняю button.isUserInteractionEnabled = true.

...