0
@IBOutlet weak var menuButton: UIButton!

@IBOutlet weak var clubButton: UIButton!

@IBOutlet weak var announcemnetsButton: UIButton!

@IBOutlet weak var eventButton: UIButton!

let transition  = CircularTransition()

override func viewDidLoad() {
    super.viewDidLoad()

    menuButton.layer.cornerRadius = menuButton.frame.size.width / 2
   clubButton.layer.cornerRadius = menuButton.frame.size.width / 2
    announcemnetsButton.layer.cornerRadius = menuButton.frame.size.width / 2
    eventButton.layer.cornerRadius = menuButton.frame.size.width / 2
    // Do any additional setup after loading the view.

}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    let secondVC = segue.destination as! NewViewController
    secondVC.transitioningDelegate = self
    secondVC.modalPresentationStyle = .custom
    let thirdVC = segue.destination as! ClubsViewController
    thirdVC.transitioningDelegate = self
    thirdVC.modalPresentationStyle = .custom
    let fourthVC = segue.destination as! AnnouncementsViewController
    fourthVC.transitioningDelegate = self
    fourthVC.modalPresentationStyle = .custom
    let fifthVC = segue.destination as! EventsViewController
    fifthVC.transitioningDelegate = self
    fifthVC.modalPresentationStyle = .custom
}

I am running this code but I keep getting the error, what am I doing wrong? I believe everything is linked correctly, but I keep getting the SIGABRT error.

jignesh Vadadoriya
  • 3,244
  • 3
  • 18
  • 29

2 Answers2

0

Every Segue has a identifier. You have to set identifier for segue

In the prepare you are not checking the segue identifier. Due to that you are trying to forcefully convert the segue.destination controller four different controller, which is wrong.

Please see how to set segue identifier

And change your code based on your segue identifier

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "NewVC" {
            let secondVC = segue.destination as! NewViewController
            secondVC.transitioningDelegate = self
            secondVC.modalPresentationStyle = .custom
        } else if segue.identifier == "ClubVC" {
            let thirdVC = segue.destination as! ClubsViewController
            thirdVC.transitioningDelegate = self
            thirdVC.modalPresentationStyle = .custom
        } else if segue.identifier == "AnnouncementVC" {
            let fourthVC = segue.destination as! AnnouncementsViewController
            fourthVC.transitioningDelegate = self
            fourthVC.modalPresentationStyle = .custom
        } else if segue.identifier == "EventVC" {
            let fifthVC = segue.destination as! EventsViewController
            fifthVC.transitioningDelegate = self
            fifthVC.modalPresentationStyle = .custom
        }
    }
Subramanian P
  • 4,365
  • 2
  • 21
  • 25
  • How can I specify a function to a certain segue? – Praneeth Kandula Jul 03 '17 at 16:20
  • Do you want to call a function based on the segue identifier? – Subramanian P Jul 03 '17 at 16:26
  • if I want to specify this code, to a certain button or segue, how would I do it: func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { transition.transitionMode = .present transition.startingPoint = menuButton.center transition.circleColor = menuButton.backgroundColor! return transition – Praneeth Kandula Jul 03 '17 at 16:31
  • However, as you can see I am only editing that one button and remains that way for the rest of the buttons. But if I want to apply it to the rest of the buttons that I have, how would I? – Praneeth Kandula Jul 03 '17 at 16:41
  • Do you want to set different `transition` for different controller? – Subramanian P Jul 03 '17 at 16:46
  • Yes, ideally I would want to do that. – Praneeth Kandula Jul 03 '17 at 16:47
  • `func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { if source.isKind(of: NewViewController.self) { transition.transitionMode = .present transition.startingPoint = menuButton.center transition.circleColor = menuButton.backgroundColor! return transition } else if source.isKind(of: ClubsViewController.self) { // Different animatiomn. } }` – Subramanian P Jul 03 '17 at 16:49
  • Yes. we can discuss – Subramanian P Jul 03 '17 at 17:25
  • I have yet to reach the reputation to chat, is there a way I can contact you? – Praneeth Kandula Jul 03 '17 at 17:42
0

You seem to be converting the same segue destination to many different types of VC which it obviously cannot be all at the same time.

I think what you intended to do is to check if the segue destination is of the specific type (in which case you must not force-unwrap with !):

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let secondVC = segue.destination as? NewViewController {
         secondVC.transitioningDelegate = self
         secondVC.modalPresentationStyle = .custom
    } else if let thirdVC = segue.destination as? ClubsViewController {
         thirdVC.transitioningDelegate = self
         thirdVC.modalPresentationStyle = .custom
    } else if let fourthVC = segue.destination as? AnnouncementsViewController {
         fourthVC.transitioningDelegate = self
         fourthVC.modalPresentationStyle = .custom
    } else if let fifthVC = segue.destination as? EventsViewController {
         fifthVC.transitioningDelegate = self
         fifthVC.modalPresentationStyle = .custom
    }
}

Using segue identifiers though could be more sensible in this situation.

Then again, considering that you are always performing the same actions no matter what VC that is, maybe it's worth casting it to a generic VC (i.e. as! UIViewController and performing an action on that instead of differentiating them?

mkilmanas
  • 3,395
  • 17
  • 27