From 964bb5faab2191c4c6522e5ee49f4c2cb5ceff06 Mon Sep 17 00:00:00 2001 From: Steven Deutsch Date: Mon, 4 Dec 2017 02:03:31 -0600 Subject: [PATCH] Begin FAQs.md page --- Documentation/FAQs.md | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/FAQs.md diff --git a/Documentation/FAQs.md b/Documentation/FAQs.md new file mode 100644 index 00000000..05ca1070 --- /dev/null +++ b/Documentation/FAQs.md @@ -0,0 +1,58 @@ +# MessageKit Frequently Asked Questions + +**Why doesn't the `MessageInputBar` appear in my controller?** + +If you're using the `MessagesViewController` as a child view controller then +you have to call `becomeFirstResponder()` on your view controller. The +reason is because the `MessageInputBar` is the `inputAccessoryView` of the +`MessagesViewController`. This means that it is not in the view hierarchy of +`MessagesViewController`'s root view. + +```Swift +class ParentVC: UIViewController { + override func viewDidLoad() { + super.viewDidLoad() + let childVC = MessagesViewController() + addChildViewController(childVC) + self.view.addSubview(childVC.view) + childVC.didMove(toParentViewController:self) + self.becomeFirstResponder() + } +} +``` + +**How can I remove the `AvatarView` from the cell?** + +If you return `CGSize.zero` from the `MessagesLayoutDelegate` method +`avatarSize(for:MessageType,at:IndexPath,in:MessagesCollectionView)`, the `AvatarView` +will not be visible for that cell. + +```Swift +func avatarSize(for: MessageType, at: IndexPath, in: MessagesCollectionView) -> CGSize { + return .zero +} +``` + +**How can I dismiss the keyboard?** + +The `MessagesViewController` needs to resign the first responder. + +```Swift +let controller = MessagesViewController() +controller.resignFirstResponder() +``` + +**How can I get a reference to the `MessageType` in the `MessageCellDelegate` methods?** + +You can use `UICollectionView`'s method `indexPath(for: UICollectionViewCell)` to get the +`IndexPath` for the `MessageCollectionViewCell` argument. Using this `IndexPath`, you can +then get the `MessageType` for this cell through the `MessagesDataSource` method +`messageForItem(at:IndexPath,in:MessagesCollectionView)`. + +```Swift +func didTapMessage(in cell: MessageCollectionViewCell) { + guard let indexPath = cell.indexPath(for: cell) else { return } + guard let messagesDataSource = messagesCollectionView.messagesDataSource else { return } + let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView) +} +```