Navigate from a ViewController to an another on didSelectRowAt programmatically

后端 未结 3 984
傲寒
傲寒 2021-01-27 17:12

I have a UIViewController that contains a custom UITableView. The table has a custom UITableViewCell too.

How to navigate from the

相关标签:
3条回答
  • 2021-01-27 17:58

    UIKit Programmatically TableCell Navigate without storyboard. you have two ways to View next viewController

    1. If you want to present .......

    animating from bottom to top

    yourTableView.deselectRow(at: indexPath, animated: true)//used for single Tap
    let vC = YourViewController (nibName: "" , bundle : nil)
            vC.modalPresentationStyle = .fullScreen //this line is optional for fullscreen
            self.present(vC, animated: true , completion: nil)
    
    1. Or if you want to View your viewController normally (2 is batter) ....

    animate from right to left

    yourTableView.deselectRow(at: indexPath, animated: true)
    let vC = YourViewController()
    self.navigationController?.pushViewController(vC, animated: true)
    
    0 讨论(0)
  • 2021-01-27 18:00

    Here is a complete answer:

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let newViewController = NewViewController()
        self.navigationController?.pushViewController(newViewController, animated: true)
    }
    
    0 讨论(0)
  • 2021-01-27 18:01
     override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         let vc = yourCustomVCName (nibName: "yourCustomVC nibName" , bundle : nil)
         self.present(vc, animated: true , completion: nil)  
    }
    
    0 讨论(0)
提交回复
热议问题