ios - PrepareForSegue Swift -


i have nsuserdefault set in viewcontroller , part of in viewdidload

if  (txt1totaldefault.valueforkey("textfield1total") != nil){             textfield1total = txt1totaldefault.valueforkey("textfield1total") as! double             let t1total = nsstring(format: "textfield1total: %i", textfield1total)     } 

then have segue @ bottom of code

override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {         var destviewcontroller : secondviewcontroller = segue.destinationviewcontroller as! secondviewcontroller          destviewcontroller.totalmoneylabel.text = t1total} 

but not work because not recognise t1total, how recognise or out of if statement can read value correctly

t1total should class variable. in case method variable, because of t1total not accessible in prepareforsegue method.

pseudo code

class yourclass {     var t1total = ""     override func viewdidload()     {         if  (txt1totaldefault.valueforkey("textfield1total") != nil){             textfield1total = txt1totaldefault.valueforkey("textfield1total") as! double             t1total = nsstring(format: "textfield1total: %i", textfield1total)         }     }      override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {         var destviewcontroller : secondviewcontroller = segue.destinationviewcontroller as! secondviewcontroller          destviewcontroller.totalmoneylabel.text = t1total     } } 

using code t1total accessible in prepareforsegue


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -