GData Calendar Execution Order
I was wondering if anyone had an explanation/solution for this problem. I am using the GData API to get calendar information and store it into an NSDictionary, and accessing it later. However when I call the function to get the data, it seems as if the calendar access is happening many lines after I call the function.
In the code below, I immediately call the loadGoogleCalendarEvents, which goes and gets the events and does some more processing, but my application is "jumping" past that, adding the buttons and doing whatever else I put after it, before it gets the calendar stuff.
Does anyone have an explanation for this?
- (void)viewDidLoad
{
self.dayDictionary = [NSMutableDictionary dictionary];
[self loadGoogleCalendarEvents];
UIImage* fImage = [UIImage imageNamed:@"facebook_med"];
CGRect fbuttonFrame = CGRectMake(220, 9, 25, 25);
UIButton* fButton = [UIButton buttonWithType:UIButtonTypeCustom];
fButton.frame = fbuttonFrame;
[fButton addTarget:self action:@selector(pushFacebookButton) forControlEvents:UIControlEventTouchUpInside];
[fButton setBackgroundImage:fImage forState:UIControlStateNormal];
开发者_如何学Python [fButton setShowsTouchWhenHighlighted:YES];
UIImage* tImage = [UIImage imageNamed:@"twitter_med"];
CGRect tbuttonFrame = CGRectMake(255, 9, 25, 25);
UIButton* tButton = [UIButton buttonWithType:UIButtonTypeCustom];
tButton.frame = tbuttonFrame;
[tButton addTarget:self action:@selector(pushTwitterButton) forControlEvents:UIControlEventTouchUpInside];
[tButton setBackgroundImage:tImage forState:UIControlStateNormal];
[tButton setShowsTouchWhenHighlighted:YES];
UIButton* aButton = [[UIButton buttonWithType:UIButtonTypeInfoLight] retain];
aButton.frame = CGRectMake(285,9, 25, 25);
[aButton addTarget:self action:@selector(pushAboutButton) forControlEvents:UIControlEventTouchUpInside];
[aButton setShowsTouchWhenHighlighted:YES];
[navBar addSubview:fButton];
[navBar addSubview:tButton];
[navBar addSubview:aButton];
[super viewDidLoad];
}
Network operations on iOS are typically asynchronous. The actual fetch of data with the GData API occurs long after the call to begin the fetch has returned.
Any tasks that need to be performed after the load of calendar events has completed should be done in the callback from the GData fetch. The callback will be invoked from the application's run loop once the fetch has finished (or failed.)
精彩评论