Lim Thye Chean Lim Thye Chean - 4 months ago 132
iOS Question

Segue to popover for iPhone not working in iOS 10?

I wanted to segue to a popover in iOS 10, this piece of code used to work fine on iPhone but not now (it shows full screen), what have I done wrong? The segue is set to "Present As Popover".

override func prepare(for segue:UIStoryboardSegue, sender:AnyObject!) {
if segue.identifier == "about" {
let aboutController = segue.destination as! AboutController
aboutController.preferredContentSize = CGSize(width:300, height:440)

let popoverController = aboutController.popoverPresentationController

if popoverController != nil {
popoverController!.delegate = self
popoverController!.backgroundColor = UIColor.black
}
}
}

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}

Answer

Many function have been renamed in Swift 3, including adaptivePresentationStyleForPresentationController - this is now adaptivePresentationStyle(for:)

Change your code to

func adaptivePresentationStyle(for controller:UIPresentationController) -> UIModalPresentationStyle {
    return .none
}

Since your function name didn't match it wasn't being called and because it is an optional function in the protocol, you didn't get a warning.

Comments