update ChatExample code for AccessoryView to work properly

This commit is contained in:
subdiox
2019-02-21 04:56:38 +09:00
parent 8dee9923a8
commit 667aac9954
@@ -328,7 +328,11 @@ extension AdvancedExampleViewController: MessagesDisplayDelegate {
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
guard accessoryView.subviews.isEmpty else { return }
// The following code doesn't work properly. Use forEach method instead.
// guard accessoryView.subviews.isEmpty else { return } // not working
accessoryView.subviews.forEach{$0.removeFromSuperview()} // works
let button = UIButton(type: .infoLight)
button.tintColor = .primaryColor
accessoryView.addSubview(button)