2011-05-24 39 views
0

我想知道是否有人對此問題有解釋/解決方案。我使用GData API來獲取日曆信息並將其存儲到NSDictionary中,並在以後訪問它。但是,當我調用函數來獲取數據時,在我調用函數後,好像日曆訪問正在發生許多行。GData日曆執行順序

在下面的代碼中,我立即調用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]; 
} 

回答

1

iOS上的網絡操作通常是異步的。使用GData API實際獲取數據會在調用開始返回之後很長時間發生。

日曆事件加載完成後需要執行的任何任務應該在GData提取的回調中完成。一旦提取完成(或失敗),將從應用程序的運行循環中調用回調。

+0

非常感謝您的回答。我沒有意識到這會發生(不知道爲什麼我沒有意識到這一點),考慮到我已經完成了URL訪問,當我想要時,正確的順序發生。我能夠爲此做一些工作,並得到它的工作。 – MZimmerman6 2011-05-26 13:34:10