ios - Segue performing on separate button click -
i'm following course online, app i'm building cut down version of instagram can see on left hand side have view signing in, on right hand side have view signing up.
pretty straight forward right, have created seque signin page button register when pressed takes registration view (one on right), works expected if i'm on signin page , click sign in , errors whatever reason display error message straight after performs seque registration screen though never pressed register
this storyboard:
this code behind sign in button located on left view
@ibaction func btnsignin(sender: anyobject) { if txtusername.text == "" || txtpassword.text == "" { displayalert("error", message: "username , password required!") } } i have no other code inside controller cause seque initialise.
if can shed light how can stop seque happening on sign in click , happen when press register i'd appreciate it.
update
after further investigation seems issue alert box i'm displaying. if comment out alert box , press signin , let error yet not display click register takes me view on right, click sign in , taken view on left , press sign in display alert box , when closes seems thinks view controller that's being displayed in 1 previous current 1 on page, odd. alert function:
func displayalert(title: string, message: string) { // display alert message user. passing in title , message displayed. if #available(ios 8.0, *) { let = uialertcontroller(title: title, message: message, preferredstyle: uialertcontrollerstyle.alert) a.addaction((uialertaction(title: "ok", style: .default, handler: { (action) -> void in self.dismissviewcontrolleranimated(true, completion: nil) }))) self.presentviewcontroller(a, animated: true, completion: nil) } else { // fallback on earlier versions } }
you don't need dismiss alert view controller in action. when user selects action, alert controller automatically dismissed.
since calling dismissviewcontrolleranimated going previous view controller.

Comments
Post a Comment