iphone - Unwind Segue nil argument error -
i new ios development , trying create simple test app allows users record , edit pills in medicine cabinet.
i using ios 6.1, arc , segues.
background error:
so user has list of pills in medicine cabinet, picks 1 , segue brings him view controller gives him information pill. has option edit info segues him view controller shows current info in textfields can edit , click save button initiates unwind segue original medicine cabinet.
the error getting this. user can edit info , save , pop cabinet. when goes edit pill again, error:
*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscfstring appendstring:]: nil argument'
i did digging , found out happening. in unwind segue method,i setting properties of pill match text in textfield of editpillview controller. example, have pill , belongs jay. edit , belongs raf. using breakpoints, can see string change jay raf in unwind segue method of medicinecabinetviewcontroller. once unwind segue complete, see @ point, string gets set nil in apple's code (probably because arc deallocing memory because editpillviewcontroller no longer needed , pill's owner property becomes null pointer). when user clicks pill again, pillinfoviewcontroller trying use null pointer , boom.
i've tried many solutions try keep string stay raf such using nsstring copy method. ideas?
when unwind segue, controllers 1 you're unwinding from, not including 1 you're unwinding to, deallocated unless have strong reference them. so, pill's owner property, if it's in medicinecabinetviewcontroller, go away when controller deallocated.
there several ways can fix problem. 1 way, navigate in app using code rather using segues, can keep references controllers create, , allocate 1 if doesn't exist yet.
another way have model class that's singleton, live life of app. way data concerning medicines properties of object (or objects) in singleton class.
Comments
Post a Comment