动态 TableView 单元格到多个详细视图 Swift

Dynamic TableView Cell to Multiple Detail Views Swift

我正在使用 presentViewController 在 XCode 中的两个视图之间导航。我想知道如何从 动态 tableView select 单元格行导航到视图控制器。所以,基本上,当我点击一个动态单元格时,每个单元格都会导航到它自己的不同视图。我该怎么做? 到目前为止我有这个代码:

@IBAction func press(sender: AnyObject) {

    let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

    let vc: UINavigationController = storyboard.instantiateViewControllerWithIdentifier("newViewController") as! UINavigationController

    self.presentViewController(vc, animated: true, completion: nil)

}

但是,我不使用按钮,而是希望每个单元格都指向另一个特定视图,正如我上面所说的。

提前致谢

创建一个包含视图控制器标识符的数组:

let identifiers = ["newViewController", "newViewController2", "newViewController3"]

在您的视图控制器中实现此 UITableViewDelegate 方法:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    if let identifier = identifiers[indexPath.row] {
        let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let vc: UINavigationController = storyboard.instantiateViewControllerWithIdentifier("newViewController") as! UINavigationController
        self.presentViewController(vc, animated: true, completion: nil)
    }
}

不要忘记将 tableView 的委托设置为包含 tableview 并实现上述委托方法的视图控制器。