简体   繁体   English

没有Storyboard的TableView Cell中的iOS Swift Segue

[英]iOS Swift Segue from TableView Cell without Storyboard

I am having trouble on performing a segue when you click on a tableView's cell. 当您单击tableView的单元格时,执行序列时遇到麻烦。 I am not using storyboard at all in the application (deleted the storyboard file), and was wondering how I could perform this segue. 我根本没有在应用程序中使用情节提要(已删除情节提要文件),并且想知道如何执行此Segue。 Note: 注意:

  1. My tableView is in a different file than the viewController that displays it. 我的tableView与显示它的viewController位于不同的文件中。 So in my ViewController i have this line: 所以在我的ViewController中,我有这行:

    let tableView = MyTableView(restaurants_data: restaurants, frame: CGRect(), style: .Plain) view.addSubview(tableView) 让tableView = MyTableView(restaurants_data:餐厅,框架:CGRect(),样式:.Plain)view.addSubview(tableView)

  2. So since MyTableView.swift is the file where the didSelectRowAtIndexPath function is located at I cant do something like 因此,由于MyTableView.swift是didSelectRowAtIndexPath函数所在的文件,因此我无法执行以下操作

    self.navigationController?.showViewController(destinationVC, sender:nil) self.navigationController?.showViewController(destinationVC,sender:nil)

So, how do I perform a segue when the user clicks on the cell, given that I am using a custom TableView and my application is not using StoryBoard? 那么,假设我使用的是自定义TableView且我的应用程序未使用StoryBoard,那么当用户单击单元格时如何执行segue? Thanks a lot in advance 在此先多谢

Add a reference for the viewController inside your tableView 在tableView内为viewController添加一个引用

and initialise it in the viewController init var controller : UIViewController 并在viewController init var controller中初始化它:UIViewController

controller.presentViewController(viewControllerToPresent: UIViewController, animated: Bool, completion: block?>) controller.presentViewController(viewControllerToPresent:UIViewController,动画:Bool,完成:块?>)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM