ios4 - Objective C variable accessible by multiple methods -


this second day programming in objectivec apologize noob question.

i have viewcontroller api call using async , asihttprequest:

@synthesize loadingstatus; - (void)loadstatsdata {     [indicator sethidden:no];      loadingstatus = [nsdictionary dictionarywithobjects:[nsarray arraywithobjects:@"bad", nil] forkeys:[nsarray arraywithobjects:@"amount", nil ] ];      [restapicontroller request:@"/method.json" method:@"get" options:[nsdictionary dictionarywithobjects:[nsarray arraywithobject:@"amount"] forkeys:[nsarray arraywithobject:@"receiving"] ] parent:self]; } 

and receiving this:

- (void)requestfinished:(asihttprequest *)request {     if (receiving == @"amount")     {       // stuff       [loadingstatus setvalue:@"good" forkey:@"amount"];     }      if ([loadingstatus valueforkey:@"amount"] == @"good"])        [indicator sethidden:yes]; } 

the app crashes when tries use loadingstatus variable in requestfinished(). guess somehow variable gets dellocated, i'm unsure how approach this.

two questions: 1) how can keep loadingstatus's state across methods calls can use in way wrote code 2) there better way of achieving goal of checking if api calls completed , hiding activityindicator?

-m.

do way: refer loadingstatus self.loadingstatus

self.loadingstatus = [nsdictionary dictionarywithobjects:[nsarray arraywithobjects:@"bad", nil] forkeys:[nsarray arraywithobjects:@"amount", nil ] ]; 

that way, goes through accessor, , retain on (the @property part in .h file).

also, programming hint: break lines smaller statements easier debug.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -