swift - 以编程方式从 UiView 推送新 View Controller 的问题

标签 swift xcode uiview pushviewcontroller didselectrowatindexpath

我试图在按下 UiView 内部的按钮后显示一条消息 viewController。当我按下按钮时,消息 viewController 会自行显示,但缺少一些数据。我有一个单独的 viewController,它允许我推送 Controller 。我将在下面留下图片来展示我在说什么。

这就是消息 View Controller 应该是什么样子,这就是到达那里的代码

 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    dismiss(animated: true) {
        print("Dismiss completed")
        let user = self.user[indexPath.row]
        self.messagesController?.showChatControllerForUser(user)
    }
}

Image 1,

这就是我从 UiView 推送 View 时发生的情况,这就是到达那里的代码的样子。

        @objc func handleNewMessage() {
    let chatLogController = ChatLogController(collectionViewLayout: UICollectionViewFlowLayout())
           chatLogController.user = user

    let navVC = UINavigationController(rootViewController:chatLogController)
    self.window?.rootViewController?.present(navVC, animated: true, completion: nil)
}

image 2,

所有数据都会推送,但后退按钮丢失,并且不允许我实际发送消息。我使用两种不同的方法来访问同一个 Controller ,我希望看到相同的结果。我想知道是否有人可能是新人来解决这个问题?

最佳答案

后退按钮未显示,因为您正在使用以下函数呈现 chatLogController

@objc func handleNewMessage() {
    let chatLogController = ChatLogController(collectionViewLayout: UICollectionViewFlowLayout())
           chatLogController.user = user

    let navVC = UINavigationController(rootViewController:chatLogController)
    self.window?.rootViewController?.present(navVC, animated: true, completion: nil)
}

如果您从 messagesController 推送到 chatLogController,那么您将在 chatLogController 上显示后退按钮。

注意:当您推送到另一个 viewController 时,后退按钮会自动显示,而当您呈现 viewController 时,不会显示后退按钮。

关于swift - 以编程方式从 UiView 推送新 View Controller 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58385881/

相关文章:

arrays - 如何快速创建对象数组?

ios - 内存泄漏测试

ios - 我应该从这里去哪里? (Cocos2D+UIKit)

xcode - 为什么 switch 语句中的 'case' 是负缩进的?

iphone - UIView只接受特定区域的触摸

ios - 从概念上讲,子类化 UIView 是否正确?

ios - 使用 Kanna 解析 HTML

ios - 如何为 UINavigationController 派生对象创建初始化程序?

xcode - XCode 中的语言

ios - 在 Xcode 4.5 中针对 iOS 6 SDK 构建时 View 下降 20 像素