how to know when NSURLRequest finish loading

主宰稳场 提交于 2020-01-14 16:51:58

问题


Im implementing an app that shows some Twitter data, when is working on wifi is ok, but on 3g crashes, I have come to the conclusion that is because the NSURLRequest that fetchs the data that populates the table takes longer to load so the table ends up calling an object for key, when the keys havent even loaded,

So the question is, - how can I know when the NSURLRequest finished loading? [I checked the Class Reference but didnt see it??]

Thanks a lot!


回答1:


The delegate methods are invoked on the request's corresponding NSURLConnection, e.g.

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

You will then receive various callbacks included the finished callback as follows:

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

Other delegate callbacks are:

- (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 {


来源:https://stackoverflow.com/questions/7486491/how-to-know-when-nsurlrequest-finish-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!