以编程方式执行 segue [英] Perform a segue programmatically

查看:35
本文介绍了以编程方式执行 segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在没有 Storyboard 的情况下以编程方式执行 segue.目前我有这个作为我的代码:

Hi I'm trying to perform a segue programmatically without the Storyboard. Currently I have this as my code:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "popOutNoteExpanded" {
        let vc = segue.destination as! ExpandedCellViewController
        let cell = sender as! AnnotatedPhotoCell
        sourceCell = cell
        vc.picture = cell.imageView.image
        print("button pressed")
    }
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    performSegue(withIdentifier: "popOutNoteExpanded", sender: indexPath)
}

当我点击集合视图单元格时,它说:

When I click on the collection view cell it's saying that:

没有标识符为popOutNoteExpanded"的转场.

has no segue with identifier 'popOutNoteExpanded'.

不确定如何执行我的自定义动画过渡.

Not sure how to perform my custom animated transition.

推荐答案

Segues 是故事板的组件.如果您没有故事板,则无法执行转场.但是你可以像这样使用当前视图控制器:

Segues are components of storyboard. If you don't have a storyboard, you can't perform segues. But you can use present view controller like this:

let vc = ViewController() //your view controller
self.present(vc, animated: true, completion: nil)

这篇关于以编程方式执行 segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆