我有一个问题,我想在单个选项卡上以不同的方式打开两个 View Controller 。 喜欢: 登录屏幕 --> 主屏幕 --> 主屏幕上的两个按钮 A 和 B
1 当点击按钮A时,在选项卡 Controller tab1上打开A Controller
2 点击按钮B时,在选项卡 Controller tab1上打开B Controller
我在选项卡 Controller 中有 5 个选项卡。
请帮我解决这个问题。 请参阅随附的屏幕以获取更多帮助。
谢谢
最佳答案
你可以用这个来替换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/