swift - NavigationController 嵌套在 TabController 动画错误中

标签 swift xcode navigationcontroller

我尽力解释发生了什么。

我已将 XCode 更新至版本 10.1 (10B61)

我的 iPhone 和模拟器上的 iOS 版本是 v12.1

<小时/>

我的应用程序有一个带有 5 个选项卡的 TabController。

First: Posts
Fifth: Profile Posts

These are embedded into a navigation controller (In case someone clicks on the comments button)

所以。我注意到,如果我运行我的应用程序并单击评论,它会以一种奇怪的方式将该 vc 推送到屏幕,然后单击返回只是“颠簸”回来。向后滑动也不起作用。

但是,如果我先切换选项卡,那么一切都会正常。

VIDEO:

https://www.youtube.com/watch?v=fgS3j21L8Js

正如您在视频中看到的,切换到个人资料帖子 + 返回后一切正常。

更新1:

因此,如果我启动我的应用程序,切换到另一个选项卡,然后返回到原始选项卡,它就可以正常工作。

请求的代码:

func commentsButtonTapped(sender: UIButton) {
        let touchPoint:CGPoint = sender.convert(CGPoint.zero, to:self.tableView)
        if let indexPath = tableView.indexPathForRow(at: touchPoint) {
            openDetails(indexPath: indexPath, shouldShowKeyboard: false)
        }
    }
func openDetails(indexPath: IndexPath, shouldShowKeyboard : Bool) {
        if (self.tableView.cellForRow(at: indexPath) as? WorldMessageCell) != nil {

            let storyboard = UIStoryboard(name: "Additional", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "DetailsViewController") as! DetailsViewController

            vc.postId = PostIds.shared.nearby.ids[safe: indexPath.row]
            vc.shouldShowKeyboard = shouldShowKeyboard

            self.navigationController?.pushViewController(vc, animated: true)
        }
    }

更新2:

通过强制 TabController 在选项卡之间切换来解决问题..

override func viewDidAppear(_ animated: Bool) {

        self.selectedIndex = 1
        self.selectedIndex = 0

    }

但这不是它应该如何工作的..

更新3:

我已经测试过它,如果我将导航 Controller ->vc作为初始vc(因此没有选项卡 Controller ),则一切正常。

但是一旦导航 Controller 嵌套在选项卡中,就会发生这种情况。

我创建了一个新项目来测试这是否是版本特定的错误,但不是,一切正常。所以问题一定出在我的应用程序上。

什么会产生这样的问题(在视频中)?

最佳答案

哦..我发现了问题和错误:

因此,如果您将导航 Controller 嵌套到调用其viewDidLoad()函数的选项卡 Controller 中,那么导航 Controller 将会出现问题.

我必须完全删除的代码:

override func viewDidAppear(_ animated: Bool) {
        // here i had some code ... /

    }

现在一切正常..

关于swift - NavigationController 嵌套在 TabController 动画错误中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53180611/

相关文章:

android - 如何使用导航组件保留最后打开的 fragment

swift - 使用 Swift 和 SpriteKit 实现高级旋转行为

ios - 基于 Objective C 中 map View 框架的坐标过滤数组

ios - 将 UIButtonTypeDetailDisclosure 添加到 toolbarItems 导致运行时错误

iphone - 如何使用 iPhone 本地化资源

swift - 如何在 Xcode 中使用新的 Scene Delegate

swift - 从 navigationStack 中移除一个 ViewController 并添加它的一个新实例

ios - Cordova iOS 插件中访问各种类型的参数是如何用 Swift 编写的

swift - Alamofire 导入失败

ios - 如何在正确启动前从后台加载服务器数据