ios - 如何通过按图像导航到另一个 UIView Controller (之前在 Storyboard 中创建)

标签 ios uiview swift3 navigation

我在当前的 Storyboard中创建了一个图像,然后向其中添加了点击手势,因此现在一旦点击它我就知道了。然后我在 Storyboard中创建了另一个 UIView Controller ,它连接到名为“DetailedUIViewController.swift”的 cocatoch 类。现在,我想在单击图像后移至该 View 。

这是我的图片:

@IBOutlet weak var totalEnergy: UIImageView!

这是我的点击手势定义:

    let TGTE = UITapGestureRecognizer(target: self, action: #selector(totalEnergyFunc))
    totalEnergy.isUserInteractionEnabled = true
    TGTE.numberOfTapsRequired = 1
    totalEnergy.addGestureRecognizer(TGTE)

这是点击图像后调用的函数:

   func totalEnergyFunc(){

}

现在我想要的是如何移动到调用我的函数后先前创建的第二个 View ?

最佳答案

确保你有 DetailedUIViewControllerstoryboard ID

按 Command + Option + 3 并为 DetailedUIViewController 设置 storyboard ID

storyboard ID

totalEnergyFunc 方法中呈现 DetailedUIViewController

func totalEnergyFunc(){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "someViewController")
self.present(controller, animated: true, completion: nil)
}

关于ios - 如何通过按图像导航到另一个 UIView Controller (之前在 Storyboard 中创建),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42950890/

相关文章:

迅速-使用后台数据更新ui

ios - 如何在清晰且不同的 uiview 可以处理它们时忽略最顶层 uiview 中的触摸事件

iphone - 在 iOS 中,当 View 动画已经在设置动画时启动它会发生什么?

swift - 在 Swift 3 (libxml2) 中将 String 转换为 UnsafePointer<xmlChar> 的更快捷方式

objective-c - 启动画面在模拟器和设备上有所不同

ios - 如何设置不扭曲设备旋转的旋转变换?

string - 如何在 swift 3.0 中连接多个可选字符串?

ios - 将事件门票添加到 Apple 钱包?

ios - 无法将 IBOutlet 连接到 UIViewController(或其子类)

ios - UITableViewControllers 上的 prepareforSegue 方法