gpt4 book ai didi

swift - 点击表格 View 中的单元格时没有任何反应

转载 作者:行者123 更新时间:2023-11-30 13:20:36 25 4
gpt4 key购买 nike

我创建了一个表格 View 菜单,我希望当您点击一个单元格时显示特定的 Storyboard。菜单由 4 个单元格格式化(因此有 4 个不同的 Storyboard)

这是我的代码:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
_ = tableView.indexPathForSelectedRow!
if let _ = tableView.cellForRowAtIndexPath(indexPath){
if indexPath.row == 0{
print("User choose to buy ticket")
self.storyboard?.instantiateViewControllerWithIdentifier("SearchPage")
}else if indexPath.row == 1{
print("User choose to check the train status")
self.storyboard?.instantiateViewControllerWithIdentifier("TrainStatusPage")
}else if indexPath.row == 2{
print("User choose to see the upcoming trips")
self.storyboard?.instantiateViewControllerWithIdentifier("TripsPage")
}else if indexPath.row == 3{
print("User wants to know mor about CFR's facility")
self.storyboard?.instantiateViewControllerWithIdentifier("PassengersPage")
}
}
}

当我按下单元格(无论哪个)时,单元格会变成灰色并且没有任何反应。

enter image description here

enter image description here

最佳答案

您可能计划导航到下一个 viewController?那么你需要这么说,初始化一个实例只是工作的一半(如果这确实是你想要做的)。所以东西如下所示:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var viewController: UIViewController?
if indexPath.row == 0 {
viewController = storyboard?.instantiateViewControllerWithIdentifier("SearchPage")
}else if indexPath.row == 1 {
viewController = storyboard?.instantiateViewControllerWithIdentifier("TrainStatusPage")
}else if indexPath.row == 2 {
viewController = storyboard?.instantiateViewControllerWithIdentifier("TripsPage")
}else if indexPath.row == 3 {
viewController = storyboard?.instantiateViewControllerWithIdentifier("PassengersPage")
}

if let destination = viewController {
navigationController?.pushViewController(destination, animated: true)
}
}

关于swift - 点击表格 View 中的单元格时没有任何反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37796334/

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