Swift: Calling a segue from a different view controller delegate -
i have viewcontroller, call popover, in popover have delegate calls function in main viewcontroller.
in function close popover , want load different view controller,
the closing of original popover works, if this
func keypaddismissdata(view: uiviewcontroller, password : string){ view.dismissviewcontrolleranimated(true, completion: nil) }
however if try , call segue load new view controller code
func keypaddismissdata(view: uiviewcontroller, password : string){ view.dismissviewcontrolleranimated(true, completion: nil) self.performseguewithidentifier("logintomain", sender:nil) }
i error
warning: attempt present <uiviewcontroller: 0x7fc768488900> on ... view not in window hierarchy!
any ideas how can round this?
thanks
not sure if problem, can try:
you open popover in mainviewcontroller. dismiss popover use delegate, dismissing popover in mainviewcontroller. right after popover dismissed, want segue view.
i recreated , code looks follows:
mainviewcontroller:
protocol dismissdelegate: class { func dismiss() } class viewcontroller: uiviewcontroller, dismissdelegate { override func viewdidload() { super.viewdidload() } @ibaction func openbutton(sender: uibutton) { let popoverviewcontroller = storyboard?.instantiateviewcontrollerwithidentifier("popoverviewcontroller") as! popoverviewcontroller popoverviewcontroller.modalpresentationstyle = .popover popoverviewcontroller.delegate = self popoverviewcontroller.preferredcontentsize = cgsize(width: 200, height: 260) popoverviewcontroller.view.backgroundcolor = uicolor.yellowcolor() // settings popover let popover = popoverviewcontroller.popoverpresentationcontroller! popover.sourceview = self.view popover.sourcerect = sender.frame popover.backgroundcolor = uicolor.redcolor() presentviewcontroller(popoverviewcontroller, animated: true, completion: nil) } func dismiss() { dismissviewcontrolleranimated(true) { self.performseguewithidentifier("segue", sender: self) } } }
popoverviewcontroller:
class popoverviewcontroller: uiviewcontroller { weak var delegate: dismissdelegate? override func viewdidload() { super.viewdidload() } @ibaction func dismissbutton(sender: uibutton) { delegate?.dismiss() } }
the difference is, i've put segue in completion of dismissviewcontrolleranimated
Comments
Post a Comment