iOS Development Tutorial (2) View Jump, Page Jump

1. Application scenarios

        In practical applications, we often need to jump from one page to another. For example, if there is no account in the "login interface", we need to jump to the "registration page" to register an account, and then return to the login interface to log in. Here we need to use the view jump technology

2. Technical realization

        1. Create a new test app and name it "JumpView". How to create a new project can refer to the previous article ios development tutorial 1 (development environment construction)

        

         2. Open the Main storyboard of the newly created project, click the "+" button in the upper right corner, and build a simple login interface

         3. Add a "Navigation Controller", delete the added "Root View Controller", and then add a "View Controller", as shown in the figure below

        4. Add a "view" control in the newly created view, and then build a registration interface

         5. Hold down ctrl, click and drag the line from "Root View Controller" to "View Controller", and select "root view controller" in the pop-up menu, so that a registered view will be created

 

         6. Click the "Register" button with the mouse, hold down Ctrl and drag the mouse to "Navigation Controller", and select "Present Modally" in the pop-up menu, so that a view jump is completed

         7. Click Run, the following is the first screen we start, click the "Register" button to jump to the registration page

 3. Other technologies

         We have implemented the function of view jump here, so does anyone have a question in mind: If I want to do some processing before the view jump, such as "judging whether the jump condition is met or doing some data when jumping report" what to do. In fact, ios has left us a processing method, we can handle it by overloading this method

        1. Rewrite the "shouldPerformSegue" method, returning false means not jumping, returning true means jumping

    override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
        if(true){
            let alertController = UIAlertController(title: "请阅读用户协议并同意",message: nil, preferredStyle: .alert)
               let okAction = UIAlertAction(title: "确定", style: .cancel, handler: nil)
               alertController.addAction(okAction)
               self.present(alertController, animated: true, completion: nil)
            
            return false
        }
        
        return true
    }

Guess you like

Origin blog.csdn.net/dm569263708/article/details/130596500