ios - 在 swift 的一个选项卡项上打开两个 Controller A 和 B

标签 ios swift uitabbarcontroller

我有一个问题,我想在单个选项卡上以不同的方式打开两个 View Controller 。 喜欢: 登录屏幕 --> 主屏幕 --> 主屏幕上的两个按钮 A 和 B

1 当点击按钮A时,在选项卡 Controller tab1上打开A Controller

2 点击按钮B时,在选项卡 Controller tab1上打开B Controller

我在选项卡 Controller 中有 5 个选项卡。

请帮我解决这个问题。 请参阅随附的屏幕以获取更多帮助。

enter image description here

谢谢

最佳答案

你可以用这个来替换ViewController

 func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) -> Bool {


        let selectIndex : NSInteger = (tabBarController.viewControllers?.index(of: viewController))!

        if (selectIndex == 1) {


                let vc = UIViewController()  // your new Controller

                var allviews = tabBarController.viewControllers
                 allviews?.remove(at: selectIndex)
                 allviews?.insert(vc, at: selectIndex)
            tabBarController.setViewControllers(allviews, animated: true)


                return false;

        }

        return true;

    }

关于ios - 在 swift 的一个选项卡项上打开两个 Controller A 和 B,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45810141/

相关文章:

android - 插入移动操作系统核心应用程序

ios - 收藏 View 作为自定义键盘不起作用

实现协议(protocol)类型的swift方法参数?

ios - Swift 框架不在 -swift 文件中生成 objective-c 头代码

objective-c - 带小数的 float 四舍五入

ios Swift 图表问题

ios - 具有自定义单元格的 TableView 重复包含图像的第一个和最后一个单元格

ios - 如何在我的选项卡栏 iOS 应用程序上呈现模态 UI 导航 View ?

swift - 如何设置标签栏徽章?

iOS:UITabBarController 下面有广告