-1

I'm going to try to be very detailed about this, and I hope one of you guys can help me out.

I have a Home VC with 2 lists stacked on top of each other, list #1 always shows up on top. However, if I click on list #2 and navigate to any of the sections on that list, when I go back to Home VC, list #1 shows up instead of the last list that was clicked (list #2).

What can I do so that HomeVC shows either list #1 or list #2 depending on which one I clicked last?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • It's difficult to tell without your code. Are you doing something in your `viewDidAppear`? – Shamas S Feb 21 '19 at 14:12
  • When you present the new viewcontroller you know the row that was pressed on, so isn't it just a case of scrolling to that row when restored, or have I got the wrong end of the stick? – trojanfoe Feb 21 '19 at 14:23
  • Since I have two lists stacked on top of each other, I set up my viewDidLoad like this: override func viewDidLoad() { super.viewDidLoad() listOne.alpha = 1 listTwo.alpha = 0 } I want the Home VC to display the last list that was clicked when I exited. – Aaron Coronado Feb 21 '19 at 14:36
  • OK, same principle. You know the current state of which list is currently displayed so you just need to record this value before presenting the new view? – trojanfoe Feb 21 '19 at 14:42
  • how can I do this? – Aaron Coronado Feb 21 '19 at 14:43
  • how do you "go back" to HomeVC? do you use pushViewController? or popViewController? – Samuel Chavez Feb 21 '19 at 17:08

1 Answers1

0

In your tap action of both lists you can do something like this, you'll set it to true when you tap on the first list, and set it to false when you tap on your second list

UserDefaults.standard.set(true, forKey: "List1") //Put this when you tap the first list
UserDefaults.standard.set(false, forKey: "List1") //Put this when you tap the second list

then on your willAppear method you can do something like this

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    if(UserDefaults.standard.bool(forKey: "List1")) {
       //You tapped List1
    } else {
       //You tapped List2
    }
}

Hope this helps

Samuel Chavez
  • 768
  • 9
  • 12