TabBar disappears

Asked 2 years ago, Updated 2 years ago, 114 views

This is xcode 8.3
streetboard

The configuration of the storyboard is as above.
Click the button from screen 1 on tab 1 to transition to screen 1-2.

@IBAction funcbtnNext_click(_sender:Any){
        let next=storyboard!.instantiateViewController(withIdentifier: "SecondView")
        self.present(next, animated:true, completion:nil)
}

Then, click the button again from screen 1-2 and the tab bar disappears when you transition to screen 1.

@IBAction funcbtnNext_click(_sender:Any){
        let next=storyboard!.instantiateViewController(withIdentifier: "FirstView")
        self.present(next, animated:true, completion:nil)
}

How do I view the original tab bar even if I click the button back?

swift ios swift3

2022-09-30 21:26

1 Answers

You may know that the code for "Click the button from screen 1 on tab 1 and transition to screen 1-2" and "Click the button again from screen 1-2 and transition to screen 1" are almost the same.

There should be no tab bar in Screen 1-2 .Don't you think it's natural that the tab bar doesn't appear on the new screen 1 if you use the exact same code?

It says "If you click the button and go back", but your code "Screen 1-2 to ~" is for "Create a new screen with the same design as Screen 1 and transition to that new screen", not the code for returning to the original screen

(instantiate... means "create a new screen" or you'll have a lot of trouble in the future.)

Use the dismiss(animated:completion:) method to return to the original screen from the screen shown in the present(_:animated:completion:).

Try rewriting the btnNext_click(_:) method on the ViewController side for screen 1-2 (you may want to rename the button method "Back" with Next, but rewriting the method name with the connection on the storyboard can cause many inconveniences).

@IBAction funcbtnNext_click(_sender:Any){
    self.dismiss(animated:true, completion:nil)
}

Also, if you are going to use the storyboard anyway, you should consider using segue for the transition to the next screen and unwind segue for the return to the original screen.Personally, if you use unwind segment, it's quite troublesome, but if you search "How to use unwind segment", you'll find a good article in Japanese.


2022-09-30 21:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.