Search This Blog

Thứ Năm, 31 tháng 8, 2017

Cách chuyễn màn hình bằng NotificationCenter in IOS

override func viewDidLoad() {
        super.viewDidLoad()
        setupNotification()
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    @IBAction func Chuyen(_ sender: Any) {
     
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "goToMH"), object: nil)
        
    }
    
    func setupNotification(){
        
        NotificationCenter.default.addObserver(self, selector: #selector(self.goToMH), name: NSNotification.Name(rawValue: "goToMH"), object: nil)
        
    }
    
    func goToMH(){
        
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let VC = storyboard.instantiateViewController(withIdentifier: "MHViewController")  as! ManHinhViewController

        self.navigationController?.pushViewController(VC, animated: true)
        
    }


Không có nhận xét nào:

Đăng nhận xét