我正在使用swift 2.2和xcode 7.3。我试图在单击一行时从另一个tableview加载表视图。在
didSelectRowAtIndexPath
第一个表View的,我创建了另一个表视图类的实例,并使用pushViewController调用它。但是表格视图没有加载,屏幕保持不变。我的代码是
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
NSLog("It did enter the didselectRowAtIndexPath")
if (indexPath.section == 0){
let enrolledView = DetailsViewController()
navigationController?.pushViewController(enrolledView, animated: true)
}
if (indexPath.section == 1){
let appcatalog = AppCatalogViewController()
navigationController?.pushViewController(appcatalog, animated: true)
}
if (indexPath.section == 2){
let support = supportViewController()
navigationController?.pushViewController(support, animated: true)
}
}
注意:"确实输入了didselectRowAtIndexPath"在日志中打印出来。所以如果有些事情做得不对,请告诉我。
答案 0 :(得分:0)
你能给我们更多的代码吗?
例如,您如何在导航控制器中嵌入您的课程?
因为如果没有出现,可能是因为navigationController是nil
答案 1 :(得分:0)
我认为你的代码中有两个错误。
您还没有将控制器嵌入到UINavigation控制器中。
您可以在移动视图控制器之前启动视图控制器。首先为每个视图控制器分配一个故事板标识符。因此,请将代码更改为:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
NSLog("It did enter the didselectRowAtIndexPath")
if (indexPath.section == 0){
let enrolledView = self.storyboard?.instantiateViewControllerWithIdentifier("identifier of your DetailsViewController")
navigationController?.pushViewController(enrolledView, animated: true)
}
if (indexPath.section == 1){
let appcatalog = self.storyboard?.instantiateViewControllerWithIdentifier("identifier of your AppCatalogViewController")
navigationController?.pushViewController(appcatalog, animated: true)
}
if (indexPath.section == 2){
let support = self.storyboard?.instantiateViewControllerWithIdentifier("identifier of your supportViewController")
navigationController?.pushViewController(support, animated: true)
}
}