Navigate from UIView to UIViewController without storyboard and navigation controller

Is there a way to navigate from a UIView
, which is part of a UIViewController
, to another UIViewController
neither using storyboards nor navigation controllers?

I have a UITapGestureRecognizer which I want to navigate to another UIViewController
( BuyController()
) whenever it is tapped once. Accordingly, my code looks like this:

//handle singleTap
func singleTapOnLikesDetected(_ sender: UITapGestureRecognizer) {

    print("check") //works
    let toController = BuyController()
    BarController().pushViewController(toController, animated: true) //error occurs since BarController is no navigationcontroller

}

BarController
( UITabBarController
, UITabBarControllerDelegate
) is my rootViewController in the AppDelegate.swift
. The UIView
however belongs to another UIViewController
called HomeController
( UIViewController
, UIScrollViewDelegate
). I do not use storyboards at all and I would like to keep it that way, as I am going to work on a project in a team (thus, a programmatic solution would be very welcome)…

You can simply do this to navigate, without using navigationController
:

self.present(toController, animated: true, completion: nil)

Or Use this,

UIApplication.shared.keyWindow?.rootViewController?.present(toController, animated: true, completion: nil)
Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » Navigate from UIView to UIViewController without storyboard and navigation controller

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录