1

I try to use custom transition animation:https://github.com/AladinWay/TransitionButton

It works as it was intended, but for some reason, after switching to a new VC application, it stops. and displays the error "Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value"

I successfully localized the problem to the line

DispatchQueue.main.async {
                     self.collectionView.reloadData ()
                 }

without animation in the direct transition to VC problems arise. information is loaded and updated by reloading the view.

Perhaps the problem occurs during a direct transition to  

 self.present (secondVC, animated: true, completion: nil)

I tried to delete the self.collectionView.reloadData () line then the error does not occur. It just remains a black screen. But this is also a problem.

At first, I thought that the problem was with the pod, but I think that the problem is that there is a direct transition to the VC and the CollectionView just does not load, and when I try to upgrade, I get an error

import TransitionButton
import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var searchTextField: UITextField!




    override func viewDidLoad() {
        super.viewDidLoad()


    }

    @IBAction func buttonAction(_ button: TransitionButton) {
        button.startAnimation() // 2: Then start the animation when the user tap the button
        let qualityOfServiceClass = DispatchQoS.QoSClass.background
        let backgroundQueue = DispatchQueue.global(qos: qualityOfServiceClass)
        backgroundQueue.async(execute: {

            sleep(3) // 3: Do your networking task or background work here.

            DispatchQueue.main.async(execute: { () -> Void in
                // 4: Stop the animation, here you have three options for the `animationStyle` property:
                // .expand: useful when the task has been compeletd successfully and you want to expand the button and transit to another view controller in the completion callback
                // .shake: when you want to reflect to the user that the task did not complete successfly
                // .normal
                button.stopAnimation(animationStyle: .expand, completion: {
                    let secondVC = CarInfo()
                    self.present(secondVC, animated: true, completion: nil)
                })
            })
        })
    }
}

import TransitionButton
import UIKit

class CarInfo: CustomTransitionViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {

    @IBOutlet weak var testSegue: UILabel!
    @IBOutlet weak var collectionView: UICollectionView!


    override func viewDidLoad() {
        super.viewDidLoad()




        // create post request


                DispatchQueue.main.async {
                    self.collectionView.reloadData()
                }
            } catch {
                print(error)
            }

        }
        task.resume()
}

I plan to use this animation and in the background to load data from the API after displaying the finished page. But now everything just breaks

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
Сева
  • 510
  • 1
  • 4
  • 15
  • Possible duplicate of https://stackoverflow.com/questions/25474115/how-to-load-uiviewcontroller-programmatically-from-storyboard – Martin R May 08 '19 at 16:48

1 Answers1

1

You should load this vc from storyboard so replace and set a storyboard identifier like CardID

let secondVC = CarInfo()

with

let secondVC  = self.storyboard!.instantiateViewController(withIdentifier: "CardID") as! CarInfo
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
  • It worked, but it didn't quite work out the way I intended. How to save the binding to NavController to be able to go back? – Сева May 08 '19 at 21:04
  • resolve need replace `self.present(secondVC, animated: true, completion: nil)` from `self.performSegue(withIdentifier: "navSegue", sender: self)` navSegue is identifier for segue which I have connected the two I need VC – Сева May 08 '19 at 21:58
  • your main problem which is the point of the question is loading the vc , using segue/present is your choice – Shehata Gamal May 08 '19 at 22:05