所以我在我的消息传递应用程序中为UIView提供了这个懒惰的var。 View包含一个文本字段和2个按钮。我们称之为 inputView 。 inputView 已经以编程方式创建,每当我通过以下方式呈现它时:present(chatLogController, animated: true)
它按预期工作。这是一张向您展示的图片:
但是,每当我将ChatLogVC放在容器视图中并通过嵌入式segue与Interface Builder呈现时,视图永远不会显示。这是一张图片
注意:我使用containerView的原因是顶部有标题栏。
为什么嵌入的segue会阻止变量被执行?
这是我的代码
介绍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:
我遗漏了所有的UI代码
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")
}
}
我的问题是:当ChatLog通过segue呈现时,为什么不执行inputView?