ios - Access data from AppDelegate in ViewController. -


i'm beginner programmer , new site , tried looking solution before asking had trouble wording sorry if has been asked before.

i'm using parse , main goal right display number of users in app in label.

in appdelegate.m

pfquery *usercountquery = [pfuser query]; [usercountquery countobjectsinbackgroundwithblock:^(int usercount, nserror *error) {     if (!error) {         // count request succeeded. log count         nslog(@"there %d users", usercount);     } else {         // request failed     } }]; 

that code gets proper number in console , i'm challenged getting variable view controller use label. there simple way or method of accomplishing flawed start?

i assume have method in appdelegate snippet, this:

@interface appdelegate { ...  - (void)countuser; } 

then can change method to:

- (void)countuserwithsuccessfulblock:(void (^)(int))successfulblock {     pfquery *usercountquery = [pfuser query];     [usercountquery countobjectsinbackgroundwithblock:^(int usercount, nserror *error) {         if (!error) {             // count request succeeded. log count             nslog(@"there %d users", usercount);             successfulblock(usercount);         } else {             // request failed         }     }]; } 

then viewcontroller:

appdelegate* appdelegate = (appdelegate*) [uiapplication shareapplication].delegate; [appdelegate countuserwithsuccessfulblock:^(int result) {     //display label; }]; 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -