A
A
Alexander Ivanov2022-02-08 21:13:28
Swift
Alexander Ivanov, 2022-02-08 21:13:28

Why doesn't it switch to another controller?

There is a test case with a basic controller

class TestController: UIViewController {
    private let button = UIButton()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.frame = CGRect(x: 0, y: 0, width: 1000, height: 1000)
        self.view.backgroundColor = .red
        print("TestController viewDidLoad")
        button.setTitle("asxsas", for: .normal)
        button.frame = CGRect(x: 5, y: 150, width: 100, height: 100)
        self.view.addSubview(button)
    }
    
}


class HomeController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    func get(){
        
        self.switchAction()
        
    }
    
    @objc func switchAction(){
        let view = TestController()
        view.view.backgroundColor = .white
        let navVC = UINavigationController(rootViewController: view)
        present(navVC, animated: true)
    }
}


The end goal is to switch from HomeController to TestController, changing the screen displayed on the phone. There are no errors, it compiles and runs, but when the function is called, nothing happens

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Araya, 2022-02-09
@Araya

The method switchActionis in a method getthat is not called anywhere

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question