Bartłomiej Semańczyk
Bartłomiej Semańczyk

Reputation: 61840

How to override one kind of segue in code?

Simply I have one segue of kind Show from FirstViewController to the SecondViewController. I call it on iPad and iPhone from two places of my FirstViewController. It is OK, but in one case I need to present SecondViewController as a .Popover.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if let secondViewController = segue.destinationViewController as? SecondViewController {

        if let cell = sender as? UITableViewCell, indexPath = tableView.indexPathForCell(cell) {

            let student = fetchedResultsController.objectAtIndexPath(indexPath) as! Student
            secondViewController.schoolClass = schoolClass
            secondViewController.student = student

        } else {

            secondViewController.modalPresentationStyle = .Popover
            secondViewController.schoolClass = schoolClass

            let popoverPresentationController = studentFormViewController.popoverPresentationController
            popoverPresentationController!.delegate = self
            popoverPresentationController?.permittedArrowDirections = .Up
            popoverPresentationController?.barButtonItem = addStudentBarButtonItem
        }
    }
}

It doesn't work.

How can I override kind of segue from storyboard in code?

Upvotes: 0

Views: 316

Answers (1)

Eugene Svaro
Eugene Svaro

Reputation: 394

You should use custom segues:

  1. implement custom segue by subclassing UIStoryboardSegue class and override prepare() method. (In prepare() method you implement all required behaviour (controllers animation, presentation and so on depending on your case);
  2. Change you segue type from push to custom in the interface builder, and pick your implementation in class property (like on image below)

Using custom segue

Best regards!

Upvotes: -1

Related Questions