ios - How to cancel a segue in certain conditions (if/else)? -


this question has answer here:

i creating app. in view, there several text fields in user inputs numbers, presses button, , transported next view controller.

how make if person taps button, , 1 or more text fields empty, segue cancels?

here code area far:

override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {     if savebutton === sender {         let name = nametextfield.text ?? ""          // set meal passed meallisttableviewcontroller after unwind segue.         meal = meal(name: name)      }     if calcbutton === sender {      if weightinkilos.text == "" && percentofdehydration.text == "" && ongoinglosses.text == "" && factor.text == "" {          let alertcontroller = uialertcontroller(title: "fields left empty.", message:             "you left fields blank! please make sure fields filled in before tapping 'calculate'.", preferredstyle: uialertcontrollerstyle.alert)         alertcontroller.addaction(uialertaction(title: "dismiss", style: uialertactionstyle.default,handler: nil))          self.presentviewcontroller(alertcontroller, animated: true, completion: nil)      }      else {         let destviewcontroller: ftrviewcontroller = segue.destinationviewcontroller as! ftrviewcontroller          let weightint: int? = int(weightinkilos.text!)         let dehydrationint: int? = int(percentofdehydration.text!)         let lossesint: int? = int(ongoinglosses.text!)         let factorint: int? = int(factor.text!)          let lrs24int = (30 * weightint! + 70) * factorint! + weightint! * dehydrationint! * 10 + lossesint!          let lrsperhourint = lrs24int / 24          destviewcontroller.lrshr = "\(lrsperhourint)"         destviewcontroller.lrs24hrs = "\(lrs24int)"      }      } } 

thank you!

ps- 12 years old, , learned know programming online , in books, if answer, can please specific? again!

pss- if vague in question, tell me, , can specify :)

you must check need before calling segue.

so, user write answers, check if ok, if, ok, segue, else, alert user , ask retype info.

got it?


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -