so I have this lazy var for a UIView in my messaging app. The View holds a textfield, and 2 buttons. We'll call it inputView. inputView has been created programmatically and whenever I present it via: present(chatLogController, animated: true)
It works as expected. here is an image to show you:
However, whenever I place ChatLogVC inside of a container view and present it through an embedded segue with Interface Builder the view never gets displayed. Here is a picture
NOTE: The reason I am using the containerView is to have the header bar at the top.
Why would an embedded segue prevent the variable to be executed?
Here's my code
Presenting VC:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
**MARK: Performs the function below
self.showChatControllerForUser(user)
**MARK: Performs segue to VC which then performs the embed segue
self.performSegue(withIdentifier: "toChatLog", sender: nil)
}
**MARK: This function shows successfully the inputView
func showChatControllerForUser(_ user: messageUser) {
let chatLogController = ChatLogController(collectionViewLayout: UICollectionViewFlowLayout())
chatLogController.user = user
present(chatLogController, animated: true)
//navigationController?.pushViewController(chatLogController, animated: true)
}
ChatLogVC :
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.collectionViewLayout = UICollectionViewFlowLayout()
user = segueUser
observeMessages()
print("CHAT LOG IS RUNNING")
collectionView?.showsVerticalScrollIndicator = false
collectionView?.contentInset = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
// collectionView?.scrollIndicatorInsets = UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 0)
collectionView?.alwaysBounceVertical = true
collectionView?.backgroundColor = UIColor.white
collectionView?.register(ChatMessageCell.self, forCellWithReuseIdentifier: cellId)
collectionView?.keyboardDismissMode = .interactive
//(inputContainerView)
collectionView?.bringSubview(toFront: inputContainerView)
}
lazy var inputContainerView: ChatInputContainerView = {
let chatInputContainerView = ChatInputContainerView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 64))
chatInputContainerView.chatLogController = self
return chatInputContainerView
}()
InputView:
I have left out all of the UI Code
class ChatInputContainerView: UIView, UITextFieldDelegate {
weak var chatLogController: ChatLogController? {
didSet {
sendButton.addTarget(chatLogController, action: #selector(ChatLogController.handleSend), for: .touchUpInside)
uploadImageView.addGestureRecognizer(UITapGestureRecognizer(target: chatLogController, action: #selector(ChatLogController.handleUploadTap)))
}
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
chatLogController?.handleSend()
return true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
My question is: Why doesn't the inputView get executed when the ChatLog is presented through a segue??