转到当前视图控制器的新实例

Segue to a New Instance of the Current View Controller

我在导航控制器中嵌入了故事板视图,它显示数据库中的记录以及 link 以查看相关记录。相关记录需要使用相同的视图来显示其数据,同时仍然维护导航堆栈,以便用户可以返回到上一条记录。请记住,一些数据需要传递给新的 viewController 并且 UI 由一个 tableView 组成,每个元素都排成一行,这个 segue 如何完成?

下面是视图。如果可能,请在 Swift 中回复任何示例代码。

一个想法-

给视图控制器一个标识符。并覆盖以下功能。

prepareForSegue

在该函数中,使用您拥有的标识符实例化视图控制器,然后将必要的数据传递给该控制器。并将其推送到导航控制器上。

希望它能奏效。

With some inspiration from this answer 和@Jassi 的指导,这是最终产品:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let vc = storyboard?.instantiateViewControllerWithIdentifier("inventoryItemDetail") as InventoryDetail
    vc.fmRecordId = item["inContainerRecordId"]! //this is the data which will be passed to the new vc
    self.navigationController?.pushViewController(vc, animated: true)
}