Monday, 15 July 2019

Navigation types in iOS



Navigation in normal approach :

let cdplvc = self.storyboard?.instantiateViewController(withIdentifier: "CDPLVC"
self.navigationController?.pushViewController(cdplvc!, animated: false)

In PageViewController : 

let cdplvc = self.storyboard?.instantiateViewController(withIdentifier: "CDPLVC"
//We need to fix it navigation
(UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.pushViewController(csvc!, animated: true)


Ex. PageViewController : https://stackoverflow.com/questions/56801714/in-pageviewcontroller-navigation-not-working

Set navigation bar back button :

 In pageViewController :

let csvc = self.storyboard?.instantiateViewController(withIdentifier: "CSVC")
let backButton = UIBarButtonItem()
//backItem.title = "Login"
backButton.barButtonTitle(titleString:"Status”)//Through extension class
(UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.self.navigationBar.topItem?.backBarButtonItem = backButton
(UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.pushViewController(csvc!, animated: true)

extension UIBarButtonItem {
    func barButtonTitle(titleString:String) { 
        title = titleString
        if UIDevice.current.userInterfaceIdiom == .pad {
            setTitleTextAttributes([NSAttributedString.Key.font: UIFont(name: "Medium", size: 20)!], for: UIControl.State.normal);
        } else {
            setTitleTextAttributes([NSAttributedString.Key.font: UIFont(name: "Medium", size: 15)!], for: UIControl.State.normal);
        }        
    }
}

In Normal approach :

let cdplvc = self.storyboard?.instantiateViewController(withIdentifier: "CDPLVC"
        
let backItem = UIBarButtonItem()
backItem.title = "Login"
self.navigationItem.backBarButtonItem = backItem
//If required font size etc…
if UIDevice.current.userInterfaceIdiom == .pad {
     backItem.setTitleTextAttributes([NSAttributedString.Key.font: UIFont(name: "Medium", size: 20)!], for: UIControl.State.normal);
} else {
     backItem.setTitleTextAttributes([NSAttributedString.Key.font: UIFont(name: "Medium", size: 15)!], for: UIControl.State.normal);
}
        

self.navigationController?.pushViewController(cdplvc!, animated: false)





No comments:

Post a Comment

Difference between == and ===

Difference between == and === https://stackoverflow.com/questions/24002819/difference-between-and == operator checks if their ...