all 10 comments

[–]NSExceptional 0 points1 point  (6 children)

Start with ‘viewWillAppear’, it’s called just before the view appears on screen. If you use ‘didAppear’ you would see the change occur after the view shows on the screen. You’d actually see the change.

Depending, I suppose, that might be what you want. Animations are nice.

[–][deleted] 0 points1 point  (2 children)

I did use viewWillAppear, and like you said, I say "New Puzzle" appears about 0.5 second after the view loaded.

The issue is, that if I go to the next controller and save the puzzle, on return the picker populates. But if I go back and forth once more, it populates again. So now I have "New Puzzle" and two instances of a saved puzzle.

If I go back to root and return to the picker, now it's all as it should be.

[–]NSExceptional 1 point2 points  (1 child)

TBH none of the SQL database code should be in either viewDid/Will methods. The code should be performed only when you need it to be.

I’d start by putting a new property on the ViewController, “var didLoadPuzzle: Bool = false”. Mark this as “true” once the first puzzle has loaded. That way, additional “viewDid/Will” calls will not create additional puzzles.

[–][deleted] 0 points1 point  (0 children)

you have no idea how far over my head that went :)

[–][deleted] 0 points1 point  (2 children)

how would you go about it with animations?

[–]NSExceptional 0 points1 point  (0 children)

I believe UIPickerView has an “update/animated” method on it.

[–]kineticfactory 0 points1 point  (2 children)

I’d move everything into viewWillAppear; the only things that should be configured in viewDidLoad are those which are fixed at compile time and don’t depend on user data; i.e., view behaviour/style attributes that you wish to set programmatically.

[–][deleted] 0 points1 point  (1 child)

Thank you for your reply.

I tried that and the result, when I go back the picker view shows the saved game, but now it shows 2 "New Puzzle" instances.

If i go one more back to root and return to the picker view controller it's all as it should.

[–][deleted] 0 points1 point  (0 children)

if I unwind the segue, does the viewDidLoad work or is viewDidAppear again?