问题
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