Skip to content

Instantly share code, notes, and snippets.

@nazmulkp
Last active March 7, 2017 10:57
Show Gist options
  • Save nazmulkp/8b6927c16254e9956d99395f74eff535 to your computer and use it in GitHub Desktop.
Save nazmulkp/8b6927c16254e9956d99395f74eff535 to your computer and use it in GitHub Desktop.
How to switch views programmatically in a ViewController?
talk with segue :
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//TODO:
// showShop(shop: shops[indexPath.row])
performSegue(withIdentifier: "ShopIdentifire", sender: indexPath)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "ShopIdentifire" {
let controller = segue.destination as! ShopMenuController
controller.shop = shops[(sender as! IndexPath).row]
}
}
WithOut segue use Identifire
**If you are in a Navigation Controller:**
let viewController: ViewController = self.storyboard?.instantiateViewControllerWithIdentifier("VC") as ViewController
self.navigationController?.pushViewController(viewController, animated: true)
**Or if you just want to present a new view:**
let viewController: ViewController = self.storyboard?.instantiateViewControllerWithIdentifier("VC") as ViewController
self.presentViewController(viewController, animated: true, completion: nil)
Programaticaly UINavigation View Controller . it is not in Appdelageted:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//
// //configur stripe account
// STPPaymentConfiguration.shared().publishableKey = "pk_test_vEvSUgGexfEiKq48HXVzSzuZ"
//
// // Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
//
//
// // for colleciton view
//
let layout = UICollectionViewFlowLayout()
window?.rootViewController = UINavigationController(rootViewController: LandingPageController(collectionViewLayout: layout))
//for table view or normal view
// window?.rootViewController = UINavigationController(rootViewController: RestaurantViewController())
return true
}
}
Programaticaly UINavigation View Controller . it is not in the Appdelageted:
let viewController = RestaurantViewController()
let navigationController = UINavigationController.init(rootViewController: viewController)
self.present(navigationController, animated: true, completion: nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment