From 667aac9954cd2433c9aebb4ae4706eafb5c8e17b Mon Sep 17 00:00:00 2001 From: subdiox Date: Thu, 21 Feb 2019 04:56:38 +0900 Subject: [PATCH] update ChatExample code for AccessoryView to work properly --- .../View Controllers/AdvancedExampleViewController.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Example/Sources/View Controllers/AdvancedExampleViewController.swift b/Example/Sources/View Controllers/AdvancedExampleViewController.swift index cd95b7801..a46e3d97d 100644 --- a/Example/Sources/View Controllers/AdvancedExampleViewController.swift +++ b/Example/Sources/View Controllers/AdvancedExampleViewController.swift @@ -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)