How To Dismiss Popover From Destination View Controller in Swift -
i have main view controller has been setup in interface builder open table view controller via popover segue connected button. want able dismiss popover when item inside of popover table view selected in didselectrowatindexpath
. in objective-c can typecast the segue in prepareforsegue delegate
uistoryboardpopoversegue
and pass along uipopovercontroller
table view controller. however, in swift downcast fails because sees segue type uistorybaordpopoverpresentationsegue
(when stepping through debugger) doesn't appear public api.
here's code:
override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject!) { if segue.identifier == "showcollectionssegue" { if let collcontroller:collectionstableviewcontroller! = segue.destinationviewcontroller as? collectionstableviewcontroller { if let popoversegue = segue as? uistoryboardpopoversegue { // <-- fails collcontroller.popover = popoversegue.popovercontroller } } } }
how coerce segue uistoryboardpopoversegue
in order access popovercontroller
property?
i'm open solving problem of dismissing popover in response table view cell tap different way, seems when using segue storyboard, way dismiss popover holding onto reference popover controller somehow , way far can tell cast segue popover segue swift doesn't want let me do. ideas?
a strange problem, indeed. noticed in documentation, uistoryboardpopoversegue
not inherit class. explains why cast not work - uistoryboardsegue
not superclass. tried create new object - looks weird works:
let popoversegue = uistoryboardpopoversegue( identifier: segue.identifier, source: self, destination: segue.destinationviewcontroller uiviewcontroller) println("is there controller? \(popoversegue.popovercontroller.description)") // yes !!
edit
but controller not dismiss popover :(
the fix specify segue in interface builder "deprecated segues : popover". code expected
let popoversegue = segue uistoryboardpopoversegue if let destination = segue.destinationviewcontroller as? tableviewcontroller { destination.delegate = self self.popovercontroller = popoversegue.popovercontroller }
Comments
Post a Comment