GData日历执行顺序
我想知道是否有人对这个问题有解释/解决方案。我正在使用 GData API 获取日历信息并将其存储到 NSDictionary 中,并稍后访问它。但是,当我调用该函数来获取数据时,似乎在调用该函数后很多行都发生了日历访问。
在下面的代码中,我立即调用 loadGoogleCalendarEvents,它会获取事件并进行更多处理,但我的应用程序“跳过”了它,添加按钮并执行我在其后面放置的其他操作,然后再获取日历东西。
有人对此有解释吗?
- (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];
[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];
}
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];
[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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iOS 上的网络操作通常是异步的。使用 GData API 实际获取数据发生在开始获取的调用返回后很长时间。
日历事件加载完成后需要执行的任何任务都应在 GData 获取的回调中完成。一旦提取完成(或失败),将从应用程序的运行循环中调用回调。
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.)