gpt4 book ai didi

ios - 在 Swift 中将不同的表格单元格导航到不同的 UIVewController

转载 作者:搜寻专家 更新时间:2023-11-01 06:41:55 26 4
gpt4 key购买 nike

很抱歉重复了同样的问题,但花了很多时间后我无法弄清楚这个问题。

假设,一个 UITableView2 个 table_cell,我想从每个 table_cell 导航不同的 UIViewController。我该怎么做?

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

if indexPath.row == 0 {

// go to DetailVC_1

} else if indexPath.row == 1 {

// go to DetailVC_2

}

enter image description here

最佳答案

要么手动呈现一个新的 View Controller :

self.presentViewController(controller, animated:true, completion:nil)
// or push on a navigation controller
self.navigationController.pushViewController(controller, animated:true)

或者执行您之前在 Storyboard 中设置的转场。 (从 View Controller 拖动到 Storyboard 中的另一个 View Controller )。

self.performSegueWithIdentifier("MyIdentifier", sender: self)

使用 Storyboard时,您还可以使用多个单元格类型,并设置从每个单元格类型到新 Controller 的转场。这样新的 Controller 将自动出现。在这种情况下,您可能需要使用的唯一代码是 prepareForSegue 方法,您可以在执行 segue 之前将正确的信息传递给呈现的 Controller 。

关于ios - 在 Swift 中将不同的表格单元格导航到不同的 UIVewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34178570/

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