[英]How to call (show) another View Controller when clicked on the cell of Table View in Swift
[英]In swift iOS 8 when a cell is clicked, how do I get it to open another view controller?
我刚开始进行快速编程,已经尝试了几个小时。 任何帮助都将不胜感激。
只是覆盖: didSelectRowAtIndexPath
override func tableView(tableView: UITableView!, didSelectRowAtIndexPath path: NSIndexPath!) {
let secondViewController =
self.storyboard.instantiateViewControllerWithIdentifier("SecondViewController")
as SecondViewController
self.navigationController.pushViewController(secondViewController, animated: true)
}
若要扩展@Epic Defeater的注释,如果您的表视图控制器和目标视图控制器在同一情节提要中,请从表单元格将控件拖动到目标视图控制器。 这是一个问题,它可以执行@Klevison Matias的代码,但是您的参与较少。
segue需要一个唯一的标识符,并且在表视图控制器中,您必须实现prepareForSegue:sender:
您需要创建要打开的View Controller的实例,然后过渡到该View Controller-大概是通过将View Controller“推”到导航堆栈(导航控制器)上。
例如...
let nextViewController: MyViewController = MyViewController()
self.navigationController.pushViewController(nextViewController, animated:true)
只需将单元格中的segue添加到要与其连接的视图控制器即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.