-2

我已经尝试过了,但对我没有用:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
   let cell = collectionView.cellForItem(at: indexPath)
   cell?.layer.borderColor = UIColor.gray.cgColor
   cell?.layer.borderWidth = 0.5
        print("swift")
   let storyboard = UIStoryboard(name: "Main", bundle: nil)
   let viewController = storyboard.instantiateViewController(withIdentifier: "Action") as! UIViewController
       self.navigationController?.pushViewController(viewController, animated: true)
}
4

3 回答 3

0
*//Get reference to your tab bar.*
let tabBar:UITabBarController = self.window?.rootViewController as! UITabBarController

let navInTab:UINavigationController = tabBar.viewControllers?[1] as! UINavigationController

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let destinationViewController = storyboard.instantiateViewControllerWithIdentifier("ControllersName") as? ControllersType
navInTab.pushViewController(destinationViewController!, animated: true)

*//To whichever index you want to navigate.*

tabBar.selectedIndex = 1

**Hope this helps.**
于 2018-11-28T14:40:23.087 回答
0

您正在推送到UIViewController

你可能会推到UIViewController里面UITabbarController。要导航到UITabbarController您需要实例化UITabbarController并推送到它。

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "TabBar") as! UITabBarController
self.navigationController?.pushViewController(viewController, animated: true)
于 2018-11-28T14:10:51.150 回答
-1

您应该选择标签栏控制器,而不是它包含的 UIViewController。

一个简单的方法是使用你的故事板设置一个 segue,并在你想要启动转换时调用 performSegue。

首先设置storyboard如下:

转到标签栏 然后你可以打电话self.performSegue(withIdentifier: "logInSegue", sender: self)

logInSegue是我的 segue 的名称,但显然您应该将其更改为您在情节提要中设置的 segue 标识符)

于 2018-11-28T14:09:19.687 回答