简体   繁体   中英

iOS Navigation Back Button

I'm having a scenario, I had 3 controllers, lets assume A,B and C. When app launches I'm transitioning from A to C using segue. Later, in C by using a button I'm moving to B using segue again. So, now I'm in B when I click “Back” it is transitioning to C, but it has to move to A.

How is this possible, any hint/idea?

Put this code in B controller's back button.

for viewcontroller in self.navigationController!.viewControllers as Array {
            if viewcontroller.isKindOfClass(HomeVC) { // change HomeVC to your viewcontroller in which you want to back.  
                self.navigationController?.popToViewController(viewcontroller as! UIViewController, animated: true)
                break
            }
        }

OR If Class A is your RootView controller

self.navigationController?.popToRootViewControllerAnimated(true)

如果您的Class A viewController是root用户,则可以在后退按钮上设置以下代码:

self.navigationController?.popToRootViewControllerAnimated(true)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM