Pushing and popping view controllers.

UINavigationContoller manages views by pushing and popping them on/off the controller’ view stack. When you push an item, the current view slides off screen to the left, and the new view slides over from the right.

Today , I am going to explain how to push and pop ViewController off a UINavigatinalController Stack. And also how to allow to go to previous ViewController with the help of Swipe back gesture.

Step 1: Create Xcode Project

Now, create a new Xcode Project. This project will contain a single view controller, which is our main view controller.

Step 2: Embed UINavigationController

Now embed this view controller to UINavigationController by selecting Editor (form top menu) >> Embed In >> Navigation Controller. Double click on the title bar of the UITableViewController and name it as Example.

To Push ViewController.


let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

let nextViewController = storyBoard.instantiateViewController(withIdentifier: "SecondViewControllerStoryBoardID") as! SecondViewController

self.navigationController?.pushViewController(nextViewController, animated: true)

To Pop ViewController.

1.  To pop to previous ViewController.

self.navigationController?.popViewController(animated: true);

2. To pop to root ViewController

self.navigationController?.popToRootViewController(animated: true)

3. To pop to Specific ViewController.

let controllers = self.navigationController?.viewControllers
      for vc in controllers! {
        if vc is SomeViewController {
          _ = self.navigationController?.popToViewController(vc as! SomeViewController, animated: true) } }

Pop ViewController by Swipe back gesture.

To pop ViewController by Swipe back gesture, you need to write below line in your viewDidLoad() function of ViewController which is to be popped  and make this ViewContoller a base Class of UIGestureRecognizerDelegate.

navigationController?.interactivePopGestureRecognizer?.delegate = self

Posted

in

,

by

Recent Post

  • Future Trends in AI Chatbots: What to Expect in the Next Decade

    Artificial Intelligence (AI) chatbots have become indispensable across industries. The absolute conversational capabilities of AI chatbots are enhancing customer engagement, streamlining operations, and transforming how businesses interact with users. As technology evolves, the future of AI chatbots holds revolutionary advancements that will redefine their capabilities. So, let’s start with exploring the AI chatbot trends: Future […]

  • Linguistics and NLP: Enhancing AI Chatbots for Multilingual Support

    In today’s interconnected world, businesses and individuals often communicate across linguistic boundaries. The growing need for seamless communication has driven significant advancements in artificial intelligence (AI), particularly in natural language processing (NLP) and linguistics. AI chatbots with multilingual support, are revolutionizing global customer engagement and service delivery. This blog explores how linguistics and NLP are […]

  • How Reinforcement Learning is Shaping the Next Generation of AI Chatbots?

    AI chatbots are no longer just about answering “What are your working hours?” or guiding users through FAQs. They’re becoming conversation partners, problem solvers and even reporting managers and sales agents. What’s driving this transformation? Enter Reinforcement Learning (RL)—a type of machine learning that’s changing the way chatbots think, learn, and respond. At Codalien Technologies, […]

  • AI Chatbots for Sales Team Automation: The Critical Role of AI Sales Assistants in Automating Your Sales Team

    Sales teams are the heart of any successful business, but managing them effectively can often feel like trying to juggle flaming swords. The constant pressure to generate leads, maintain relationships, and close deals leaves your team overwhelmed, spending more time on administrative tasks than actual selling. Here’s where AI-powered sales assistants step in to completely […]

  • Transforming HR with AI Assistants: The Comprehensive Guide

    The role of Human Resources (HR) is critical for the smooth functioning of any organization, from handling administrative tasks to shaping workplace culture and driving strategic decisions. However, traditional methods often fall short of meeting the demands of a modern, dynamic workforce. This is where our Human Resource AI assistants enter —a game-changing tool that […]

  • How Conversational AI Chatbots Improve Conversion Rates in E-Commerce?

    The digital shopping experience has evolved, with Conversational AI Chatbots revolutionizing customer interactions in e-commerce. These AI-powered systems offer personalized, real-time communication with customers, streamlining the buying process and increasing conversion rates. But how do Conversational AI Chatbots improve e-commerce conversion rates, and what are the real benefits for customers? In this blog, we’ll break […]

Click to Copy