Table 查看到自定义视图控制器?

Table View To Custom View Controller?

我想知道我在一个表视图中是否有两个单元格,我想如果我单击第一个单元格它会跳转到特定的视图控制器,如果我单击第二个单元格它会跳转到另一个视图控制器。 我该怎么做?

从视图控制器中的方法 didSelectRowAtIndexPath 调用 performSegue:withIdentifier:。您可以在代码中使用不同的标识符有条件地调用 segues。

你可以在didSelectRowAtIndexPath方法中这样做:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    switch indexPath.row {
    case 0 :
        println("First cell")
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewControllerWithIdentifier("FirstViewController") as! UIViewController
        self.presentViewController(vc, animated: true, completion: nil)
    case 1 :
        println("Second Cell")
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as! UIViewController
        self.presentViewController(vc, animated: true, completion: nil)
    default:
        println("No cell selectd")
    }
}

HERE 是您的示例项目。