gpt4 book ai didi

swift - TableView 到自定义 View Controller ?

转载 作者:搜寻专家 更新时间:2023-11-01 07:34:17 27 4
gpt4 key购买 nike

我想知道我在一个 TableView 中是否有两个单元格,我希望如果我单击第一个单元格它会跳转到特定的 View Controller ,如果我单击第二个单元格它会跳转到另一个 View Controller 。我该怎么做?

最佳答案

您可以在 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是您的示例项目。

关于swift - TableView 到自定义 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30951529/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com