Skip to content

Commit

Permalink
update ChatExample code for AccessoryView to work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
subdiox committed Feb 20, 2019
1 parent 8dee992 commit 667aac9
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 667aac9

Please sign in to comment.