代码之家  ›  专栏  ›  技术社区  ›  Nishant Pathania

推送视图控制器

  •  0
  • Nishant Pathania  · 技术社区  · 7 年前

    我使用一个导航控制器作为根视图控制器,在启动应用程序时,会出现一个View Controller VC1,它有一个按钮,在按下时(在segue的帮助下)会将您带到VC2,VC2有一个表视图和5个单元格,现在我想使用push而不是segue,或者显示一个从VC2转到VC3的模式(单击单元格)。

    我用过

    let displayVC : ForWebViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ForWebViewController") as! ForWebViewController
    
    
    self.navigationController?.pushViewController(displayVC, animated: false)
    

    代码已被放置在第一个单元格单击的操作下,但没有发生任何事情。
    有人能帮忙吗

    5 回复  |  直到 7 年前
        1
  •  0
  •   Krishna Kirana    7 年前

    以编程方式添加导航控制器

    let navController = UINavigationController.init(rootViewController: VC2)
    
        2
  •  0
  •   Durdu    7 年前
    • 确保你有一个导航控制器

    let displayVC : ForWebViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ForWebViewController") as! ForWebViewController
    
    present(displayVC, animated: true, completion: nil)
    

    navigationController?.pushViewController(displayVC, animated: true)
    
        3
  •  0
  •   Naresh    7 年前

    使用此代码和脚本ID

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print(indexPath.section, indexPath.row)//It will print index and section
        let hvc = self.storyboard?.instantiateViewController(withIdentifier: "Your Storyboard ID") as! ForWebViewController//Here replace your class name
        self.navigationController?.pushViewController(hvc, animated: true)
    }
    
        4
  •  0
  •   PGDev    7 年前

    可能有一件事是你面临的问题。检查以下几点:

    一。 你把 delegate 属于 tableView VC2 . 你可以在 storyboard 自身或内部 viewDidLoad() 属于 VC2型 ,编写以下代码:

    self.tableView.delegate = self
    

    检查是否 navigationController 实例不是 nil

    self.navigationController?.pushViewController(displayVC, animated: false)
    
        5
  •  0
  •   Bhavin Kansagara    7 年前

    目标C:

    PulseNavigationController * VC3 =(PulseNavigationController*)navigationcontroller;
    
    [homeNavictrl pushViewController:VC3 animated:YES];
    

    银行代码:

    let VC3 = NewViewController()
    
    self.navigationController?.pushViewController(VC3, animated: true)