0

I have an iOS app with 3 tabs:

  • Home
  • Tab1
  • Tab2

In "Home", user can navigate to a view - UIViewcontroller1 - to view the details. When the user pressed "Back" in UIViewcontroller1 to go back to "Home", I would like to detect in Home viewDidLoad() that the user came here by pressing "Back" in UIViewcontroller1.

Is there a simple way to detect this?

juan.facorro
  • 9,791
  • 2
  • 33
  • 41
Michael
  • 3,699
  • 4
  • 26
  • 27

2 Answers2

2

A delegation pattern could solve that issue.

You should have a look at this post:

Passing data between View Controllers

Community
  • 1
  • 1
guardabrazo
  • 1,219
  • 1
  • 13
  • 26
2

I know of a couple of ways to do this, none of them is exactly what you want but they might work.

First, you can detect the back on UIViewController1's viewWillDisappear, like this:

if ([self.navigationController.viewControllers indexOfObject:self] == NSNotFound) {
    //Do what you want to do here
}

Second, you could make Home UIViewController1's delegate and call whatever method you want.

Third, you could set a variable when Home pushes UIViewController1 onto the stack and check it on viewDidAppear.

Murillo
  • 1,043
  • 8
  • 9