简体   繁体   English

在Swift中单击Table View的单元格时如何调用(显示)另一个View Controller

[英]How to call (show) another View Controller when clicked on the cell of Table View in Swift

I'm new in Swift. 我是Swift的新手。 I want to learn that, how to call another View Controller when the user clicks on cell of Table View. 我想学习如何在用户单击“表格视图”的单元格时调用另一个视图控制器。 Thanks in advance. 提前致谢。

write following code : 编写以下代码:

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("showItemDetail", sender: tableView)}

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "showItemDetail" {
    let indexPath:NSIndexPath = self.tableView.indexPathForSelectedRow()!
    let detailVC:ItemDetailViewController = segue.destinationViewController as ItemDetailViewController
    detailVC.item = items[indexPath.row] as Item
}

} }

add a viewController from storyboard and add a segue from tableview cell to viewController with identifier "showItemDetail"; 从情节提要中添加一个viewController,并从tableview单元格中添加一个序列到具有标识符“ showItemDetail”的viewController中; will navigate too detailViewController 将会浏览太多detailViewController

In First View Controller 在First View Controller中

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!)
{
   if segue.identifier == "showItemDetail" 
   {
    let indexPath:NSIndexPath = self.tableView.indexPathForSelectedRow()!
    let destination = segue.destinationViewController as DetailViewController
    destination.name = "llkin Elimov"
}

In second Detail View Controller 在第二个Detail View Controller中

public DetailViewController
{
    var name = "name" as String //After you created the segue in      main.storyboard, in name , you will get your parsed string automatically

}

Hope my code is clear for you :) 希望我的代码对您清楚:)

暂无
暂无

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

相关问题 在 Swift 中单击表视图单元格时如何显示新的视图控制器 - How to show new View Controller when a Table View Cell is clicked in Swift 在表视图单元格中单击按钮时如何使用参数调用视图控制器 - How to call view controller with parameters when button clicked in table view cell 在快速的iOS 8中,当单击一个单元格时,如何获取它以打开另一个视图控制器? - In swift iOS 8 when a cell is clicked, how do I get it to open another view controller? 如何判断从另一个View Controller单击哪个表格单元格? IOS 7 - How to tell which table cell was clicked from another View Controller? iOS 7 如何使用在另一个视图控制器中输入的值填充表格视图单元格? - How to populate the table view cell with values entered in another view controller? 表视图单元格到另一个视图控制器 - Table view cell to another view controller Swift:当用户点击Tableview单元格时,如何将数据从一个视图控制器转移到另一个 - Swift: How to SHIFT data from one view controller to another when the user taps on the Tableview Cell 当数据源和委托与View Controller分开时,如何将Table View的单击项发送到其他View Controller - How to send clicked item of Table View to other view controller when datasource and delegate are separate from View Controller 如何将信息从一个视图控制器中的表视图单元传递到另一视图控制器? - How do I pass information from a table view cell in one view controller to another view controller? 单击搜索栏时如何导航到另一个视图控制器 - How to navigate to another view controller when search bar is clicked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM