2011-09-20 96 views
3

即時通訊實現一個應用程序,顯示一些Twitter數據,當工作在WiFi是好的,但在3g崩潰,我得出的結論是,因爲NSURLRequest獲取數據填充該表需要更長的時間才能加載,因此當表甚至沒有加載密鑰時,表最終會調用對象的密鑰,所以問題是,我怎麼知道NSURLRequest何時完成加載? [我檢查了類參考,但沒有看到它?]如何知道什麼時候NSURLRequest完成加載

非常感謝!

回答

9

在請求的相應NSURLConnection上調用委託方法,例如,

urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; 

然後,您會收到各種回調包括完成回調如下:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{} 

其他委託回調是:

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 

- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection{ 

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { 
相關問題