swift - How to get back to viewcontroller in alertview -
i tried viewcontroller when user press go home in alertview , show me error ( libc++abi.dylib: terminating uncaught exception of type nsexception )
@ibaction func roundbutton(sender: anyobject) { //add alert alertcontroller = uialertcontroller(title: "return home", message: "are sure???", preferredstyle: .alert) let alertaction1 = uialertaction(title: "cancel", style: .default) { (action) in } let alertaction2 = uialertaction(title: "go home", style: .destructive) { (action) in let nv = self.storyboard!.instantiateviewcontrollerwithidentifier("storyboardidentifier") as! viewcontroller self.presentviewcontroller(nv, animated:true, completion:nil) } alertcontroller?.addaction(alertaction2) alertcontroller?.addaction(alertaction1) self.presentviewcontroller(alertcontroller!, animated: true, completion: nil) //end alert }
since didn't provide information, there lot of possibilities. try cover of them.
let's presenting alert in bviewcontroller
. , want aviewcontroller
.
if aviewcontroller
, bviewcontroller
embedded in uinavgationcontroller
, have connect unwind segue between bviewcontroller
, aviewcontroller
.
first, in aviewcontroller
, add method:
@ibaction func unwind(segue: uistoryboardsegue) { }
in storyboard, control-drag bviewcontroller
"exit" of `aviewcontroller , select "unwind:" aka method declared. should see
now give segue added identifier, "unwindtohome".
in uialertaction
call closure, initiate segue:
self.performseguewithidentifier("unwindtohome", sender: self)
and that's it!
if presenting bviewcontroller
modally, things simpler, call dismissviewcontrolleranimated
:
self.dismissviewcontrolleranimated(true, completion: nil)
Comments
Post a Comment