File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,9 @@ class AnimalsViewController: UIViewController {
2727 override func viewDidLoad( ) {
2828 super. viewDidLoad ( )
2929
30- setupView ( )
30+ if animals == nil {
31+ setupView ( )
32+ }
3133
3234 if traitCollection. forceTouchCapability == . available {
3335 registerForPreviewing ( with: self , sourceView: view)
@@ -38,6 +40,7 @@ class AnimalsViewController: UIViewController {
3840 super. viewWillAppear ( animated)
3941
4042 guard let index = selectedIndex else {
43+ tableView. reloadData ( )
4144 return
4245 }
4346 updateAnimalState ( atIndex: index)
@@ -63,10 +66,10 @@ class AnimalsViewController: UIViewController {
6366 selectedIndex = IndexPath ( row: 1 , section: 0 )
6467 performSegue ( withIdentifier: segueIdentifier, sender: nil )
6568 case . OpenRandomAnimal:
66- guard let animals = self . animals else {
67- return false
69+ if animals == nil {
70+ setupView ( )
6871 }
69- let randomNumber = Int ( arc4random_uniform ( UInt32 ( animals. count) ) )
72+ let randomNumber = Int ( arc4random_uniform ( UInt32 ( animals! . count) ) )
7073 selectedIndex = IndexPath ( row: randomNumber, section: 0 )
7174 performSegue ( withIdentifier: segueIdentifier, sender: nil )
7275 default :
You can’t perform that action at this time.
0 commit comments